简体   繁体   中英

Unable to start a MySQL Container & attach it to the Docker network

I am following Docker Labs tutorial & have made it to the 7th step. Where I need to Attach MySQL DB container to my app network container. Upon entering the following command on windows 10 CMD:

docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7

I get this error:

C:\Users\Ajmal .M\getting-started>docker run -d \
docker: invalid reference format.
See 'docker run --help'.

C:\Users\Ajmal .M\getting-started>    --network todo-app --network-alias mysql \
'--network' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Ajmal .M\getting-started>    -v todo-mysql-data:/var/lib/mysql \
'-v' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Ajmal .M\getting-started>    -e MYSQL_ROOT_PASSWORD=secret \
'-e' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Ajmal .M\getting-started>    -e MYSQL_DATABASE=todos \
'-e' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Ajmal .M\getting-started>    mysql:5.7
The filename, directory name, or volume label syntax is incorrect.

CMD Snapshot

The reason you're getting this error is because it's trying to run each line as an individual command instead of one docker command.

On windows instead of \\ for a new line use ^

docker run -d ^
--network todo-app --network-alias mysql ^
-v todo-mysql-data:/var/lib/mysql ^
-e MYSQL_ROOT_PASSWORD=secret ^
-e MYSQL_DATABASE=todos ^
mysql:5.7

The command above is the same as this one line command:

docker run -d --network todo-app --network-alias mysql -v todo-mysql data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=todos mysql:5.7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM