1、查找Docker Hub上的mysql镜像[root@localhost /]#docker search mysql

2、拉取官方的镜像[root@localhost /]#docker pull mysql:5.7

3、查看镜像[root@localhost /]#docker images mysql

4、创建并运行mysql容器[root@localhost /]#docker run -d -p 3306:3306 --name mysql -v /usr/local/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root --restart=always mysql:5.7

5、查看创建的容器[root@localhost /]#docker ps | grep mysql

6、查看容器的ip地址[root@localhost /]#docker inspect --format='{{.NetworkSettings.IPAddress}}' mysql

7、查看firewalld状态[root@localhost /]# systemctl status firewalld

8、开启firewalld(可选,未开启时执行)[root@localhost /]# systemctl start firewalld

9、开放3306端口[root@localhost /]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

10、重新载入[root@localhost /]# firewall-cmd --reload

11、查看是否生效[root@localhost /]# firewall-cmd --zone=public --query-port=3306/tcp
