docker pull mysql:8
docker images
mkdir -p $PWD/mysql8-dev/{conf,data,log}
vim mysql8-dev/conf/my.conf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
secure_file_priv=/var/lib/mysql
default-time_zone = '+8:00'
# Custom config should go here
!includedir /etc/mysql/conf.d/
# 更改字符集 如果想Mysql在后续的操作中中文不出现乱码,则需要修改配置文件内容
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
docker run --restart=always -d
-v /usr/local/mysql8-dev/conf/my.cnf:/etc/mysql/my.cnf
-v /usr/local/mysql8-dev/conf/logs:/logs
-v /usr/local/mysql8-dev/data/mysql:/var/lib/mysql
-p 3306:3306
--name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:8
参数解释说明:
参数 | 解释 |
---|---|
–restart=always | 开机启动容器,容器异常自动重启 |
-d | 以守护进程的方式启动容器 |
-v /usr/local/mysql8-dev/conf/my.cnf | 映射配置文件 |
-p 3306:3306 | 绑定宿主机端口 |
–name mysql | 指定容器名称 |
-e MYSQL_ROOT_PASSWORD=123456 | 写入配置root密码 |
docker images
该指令还能够携带-q参数:docker images -q , -q表示仅显示镜像的 id: