docker -v
Docker version 18.06.1-ce, build e68fc7a
拉取 docker mysql 最新的镜像
docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
a5a6f2f73cd8: Pull complete
936836019e67: Pull complete
283fa4c95fb4: Pull complete
1f212fb371f9: Pull complete
e2ae0d063e89: Pull complete
5ed0ae805b65: Pull complete
0283dc49ef4e: Pull complete
a7e1170b4fdb: Pull complete
88918a9e4742: Pull complete
241282fa67c2: Pull complete
b0fecf619210: Pull complete
bebf9f901dcc: Pull complete
Digest: sha256:b7f7479f0a2e7a3f4ce008329572f3497075dc000d8b89bac3134b0fb0288de8
Status: Downloaded newer image for mysql:latest
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest f991c20cb508 2 weeks ago 486MB
hello-world latest e38bc07ac18e 7 months ago
docker run -p 3306:3306 --name mysql -v $PWD/data:/var/lib/msql -e MYSQL_ROOT_PASSWORD=****** -d mysql
c0d6a4dc985c8b5acd43f3883138d9c4aec34c0546c3928fee5ded9ba08c379a
docker: Error response from daemon: driver failed programming external connectivity on endpoint mysql (4b3919e1648f2d1623be615d14ba772979d3c9a86cf90b55308bef32e4cf3507): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use.
错误信息,3306 端口已被客户机使用
换个端口再试一次
docker run -p 3308:3306 --name mysql -v $PWD/data:/var/lib/msql -e MYSQL_ROOT_PASSWORD=**** -d mysql
docker: Error response from daemon: Conflict. The container name "/mysql" is already in use by container "c0d6a4dc985c8b5acd43f3883138d9c4aec34c0546c3928fee5ded9ba08c379a". You have to remove (or rename) that container to be able to reuse that name.
错误信息,docker name 已被使用
换个名称再试一次
docker run -p 3308:3306 --name mymysql -v $PWD/data:/var/lib/msql -e MYSQL_ROOT_PASSWORD=***** -d mysql
5b4ddc12b0dbe0f1e419055bee01ab2838aa4a4d9f69dd28e3f5213a9eed7473
这次没有错误提示,那就是成功了
查看 docker 进程
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b4ddc12b0db mysql "docker-entrypoint.s…" 14 seconds ago Up 10 seconds 33060/tcp, 0.0.0.0:3308->3306/tcp mymysql
连接 docker-mysql ,一切征程
关闭容器
docker stop mymysql