前置条件:已安装部署完成docker环境
1.拉取镜像
[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
a076a628af6f: Pull complete
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1831ac1245f4: Pull complete
37677b8c1f79: Pull complete
27e4ac3b0f6e: Pull complete
7227baa8c445: Pull complete
Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
2.查看是否拉取正常
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 3 weeks ago 449MB
openzipkin/zipkin latest c0f8fe2f05f5 15 months ago 157MB
rabbitmq 3.8.0-management 5788d93cd8ad 15 months ago 180MB
hello-world latest fce289e99eb9 2 years ago 1.84kB
hub.c.163.com/springcloud/eureka latest 1472b2efca4f 2 years ago 190MB
redis 4.0.8 4760dc956b2d 2 years ago 107MB
rabbitmq 3.7.3-management 2f415b0e9a6e 2 years ago 151MB
3.运行mysql
[root@localhost ~]# sudo docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
WARNING: IPv4 forwarding is disabled. Networking will not work.
c828437a15ae88919653222bbe0bd950d0e9b3b0f38af5a18e8e0a0e16c14512
备注:
启动参数如下:
mysql
建立目录映射如下:
duso docker run -p 3306:3306 --name mysql -v /usr/local/docker/mysql/conf:/etc/mysql -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
原文:https://www.cnblogs.com/zhangdongfang/p/14402632.html