转载:https://www.runoob.com/docker/docker-install-mysql.html
1 查找Docker Hub上的MySQL镜像
➜ ~ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 8221 [OK]
mariadb MariaDB is a community-developed fork of MyS… 2804 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 611 [OK]
centurylink/mysql Image containing mysql. Optimized to be link… 60 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 53
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 45
deitch/mysql-backup Automated and scheduled mysql database dumps… 36 [OK]
tutum/mysql Base docker image to run a MySQL database se… 32
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 28 [OK]
bitnami/mysql Bitnami MySQL Docker Image 27 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 20
prom/mysqld-exporter 18 [OK]
centos/mysql-56-centos7 MySQL 5.6 SQL database server 13
circleci/mysql MySQL is a widely used, open-source relation… 11
mysql/mysql-router MySQL Router provides transparent routing be… 11
arey/mysql-client Run a MySQL client from a docker container 9 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
yloeffler/mysql-backup This image runs mysqldump to backup data usi… 6 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 4 [OK]
frodenas/mysql A Docker Image for MySQL 2 [OK]
jelastic/mysql An image of the MySQL database server mainta… 1
monasca/mysql-init A minimal decoupled init container for mysql 0
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK]
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 0 [OK]
astronomerio/mysql-sink MySQL sink
2 拉取官方的镜像,标签为5.6
➜ ~ docker pull mysql:5.6
5.6: Pulling from library/mysql
743f2d6c1f65: Already exists
3f0c413ee255: Pull complete
aef1ef8f1aac: Pull complete
f9ee573e34cb: Pull complete
3f237e01f153: Pull complete
c834d5397c17: Pull complete
167b4b0bb213: Pull complete
8e13de731ad8: Pull complete
0dcd497f8ff9: Pull complete
82d36065c763: Pull complete
f30363b0dfa6: Pull complete
Digest: sha256:31b964a5d6a498fd7bae1c89e3c913b365c449f70706b075c65dbea405ff6db2
Status: Downloaded newer image for mysql:5.6
3 运行容器
docker run -p 13306:3306 --name grace_mysql -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
-p 13306:3306: 容器3306端口映射到主机的13306端口。
-v -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 。
-e MYSQL_ROOT_PASSWORD=123456: 初始化 root 用户的密码。