Docker MySQL
Docker 下 MySQL 的安装
# 搜索 mysql 镜像
docker search mysql
# 通常输出:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relati... 4511 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Crea... 310 [OK]
centurylink/mysql Image containing mysql. Optimized to be li... 51 [OK]
zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 42 [OK]
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 23 [OK]
imega/mysql Size: 149 MB, alpine:3.5, Mysql Server: 10... 11 [OK]
# ...
# 拉取 mysql 镜像
# 这里选择 mysql/mysql-server(size:200+MB),而不选择 mysql(size:400+MB)
docker pull mysql/mysql-server
# 看网络情况,等待即可...
# 拉取完成后,可以查看下本地镜像列表
docker image list
# 通常输出:
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/mysql-server latest 3ab554875eb9 2 weeks ago 215MB
# 基于 mysql 镜像启动一个 mysql 容器
# run 命令会先创建一个容器,再运行
# --env 环境参数中必须设置 mysql 的 root 密码,不然启动失败.
docker container run
--name=mysql-1
--publish=3306:3306
--volume=/data/mysql/:/var/lib/mysql/
--restart=always
--env=MYSQL_ROOT_PASSWORD=mysqllPassword
-d mysql/mysql-server
# 查看容器列表
docker container list
# mysql 容器启动成功的话,通常输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82111d39fc1e mysql/mysql-server "/entrypoint.sh my..." 8 seconds ago Up 7 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-1
Tips:MySQL 默认会把 root 用户限制为只允许本地登录,意味着不做任何修改的情况下,我们是没法远程访问该 mysql 数据库的, 解决办法.