[root@izwz90lvzs7171wgdhul8az ~]# docker pull mysql:5.6 5.6: Pulling from library/mysql 8f91359f1fff: Pull complete 6bbb1c853362: Pull complete e6e554c0af6f: Pull complete f391c1a77330: Pull complete 414a8a88eabc: Pull complete ced966b42b0e: Pull complete 509b7d623b06: Pull complete 94a03dec9143: Pull complete d40a4af51b78: Pull complete e01756c8536e: Pull complete 327b60c1a0e5: Pull complete Digest: sha256:07ebe49dc810444e172c2b5a72ae1a23ad9f4942bfe70a7f0a578590da610579 Status: Downloaded newer image for mysql:5.6 docker.io/library/mysql:5.6
等待下載完成後,咱們就能夠在本地鏡像列表裏查到REPOSITORY爲mysql,標籤爲5.6的鏡像。mysql
[root@izwz90lvzs7171wgdhul8az ~]# docker images | grep mysql mysql 5.6 95e0fc47b096 3 weeks ago 257MB
[root@izwz90lvzs7171wgdhul8az ~]# docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6 64bc48daaa60a66262a3356d7027e5dad12b903ad7433b79138dae4b5b1eb98e
命令說明:sql
-p 3306:3306:將容器的 3306 端口映射到主機的 3306 端口。docker
-v $PWD/conf:/etc/mysql/conf.d:將主機當前目錄下的 conf/my.cnf 掛載到容器的 /etc/mysql/my.cnf。安全
-v $PWD/logs:/logs:將主機當前目錄下的 logs 目錄掛載到容器的 /logs。服務器
-v $PWD/data:/var/lib/mysql :將主機當前目錄下的data目錄掛載到容器的 /var/lib/mysql 。tcp
-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用戶的密碼。阿里雲
[root@izwz90lvzs7171wgdhul8az ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 64bc48daaa60 mysql:5.6 "docker-entrypoint.s?? 3 seconds ago Up 1 second 0.0.0.0:3306->3306/tcp mymysql
注意:若是咱們使用的是阿里雲等雲服務器的,要注意是否須要添加安全組規則。
最後,能夠看到,鏈接是沒問題的:
3d