赞
踩
声明:
本文用于本人技术学习和备忘。水平有限,如有错漏欢迎指正!
原创不易,如有转载请标注出处:https://blog.csdn.net/luyou0401/article/details/126582675
https://hub.docker.com/_/mysql
# 默认版本 latest
docker pull mysql
# 如需指定版本,如下
docker pull mysql:5.7
操作如下:
# 拉取镜像 luyou@MacBook-Pro-yaco ~ % docker pull mysql Using default tag: latest latest: Pulling from library/mysql 72a69066d2fe: Pull complete 93619dbc5b36: Pull complete 99da31dd6142: Pull complete 626033c43d70: Pull complete 37d5d7efb64e: Pull complete ac563158d721: Pull complete d2ba16033dad: Pull complete 688ba7d5c01a: Pull complete 00e060b6d11d: Pull complete 1c04857f594f: Pull complete 4d7cfa90e6ea: Pull complete e0431212d27d: Pull complete Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 Status: Downloaded newer image for mysql:latest docker.io/library/mysql:latest # 查询镜像 luyou@MacBook-Pro-yaco ~ % docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 3218b38490ce 8 months ago 516MB
结果:
根据需要创建本地目录
用途 | docker目录 | 本地目录 |
---|---|---|
配置文件 | /etc/mysql | /Users/luyou/docker/mysql8/conf |
数据文件 | /var/lib/mysql | /Users/luyou/docker/mysql8/data |
日志文件 | /var/log/mysql | /Users/luyou/docker/mysql8/log |
docker run \
--name mysql \
-p 3306:3306 \
-v /Users/luyou/docker/mysql8/log:/var/log/mysql \
-v /Users/luyou/docker/mysql8/data:/var/lib/mysql \
-v /Users/luyou/docker/mysql8/conf:/etc/mysql/conf.d/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:latest
操作如下:
luyou@MacBook-Pro-yaco ~ % docker run \
--name mysql \
-p 3306:3306 \
-v /Users/luyou/docker/mysql8/log:/var/log/mysql \
-v /Users/luyou/docker/mysql8/data:/var/lib/mysql \
-v /Users/luyou/docker/mysql8/conf:/etc/mysql/conf.d/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:latest
bba03ab74d3d8eda190559789f1ae2fe2b31f212a50e183d87a80c3e6568f3b3
luyou@MacBook-Pro-yaco ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bba03ab74d3d mysql:latest "docker-entrypoint.s…" 16 seconds ago Up 14 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
结果:
命令行:
docker start mysql
图形界面:
命令行:
docker stop mysql
图形界面:
命令行:
docker rm mysql
图形界面:
命令行:
docker logs -f mysql
图形界面:
# 进入容器
docker exec -it mysql bash
# 退出容器
exit
声明:
本文用于本人技术学习和备忘。水平有限,如有错漏欢迎指正!
原创不易,如有转载请标注出处:https://blog.csdn.net/luyou0401/article/details/126582675
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。