- 1. 拉取镜像
sudo docker pull mysql
2. 创建mysql配置文件目录
mkdir -p /opt/module/mysql/conf /opt/module/mysql/data /opt/module/mysql/conf/config.d/
3. 创建mysql 配置文件
touch /opt/module/mysql/conf/my.cnf
4. 对 3 my.cnf 添加配置, 如果mysql状态一直显示restarting 就将最后一行删除
[client] default-character-set = utf8mb3 [mysqld] datadir = /opt/module/mysql/data character_set_server = utf8mb3 collation_server = utf8mb3_general_ci secure-file-priv= symbolic-links=0 !includedir /opt/module/mysql/conf/config.d/
5. 加载容器到 docker
docker run --restart=unless-stopped -d --name mysql -v /opt/module/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /opt/module/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=cmcc1234 mysql
6. 启动 docker
systemctl docker start