docker pull mysql:5.7
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql57
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
volumes:
- /docker/mysql57/data:/var/lib/mysql
- /docker/mysql57/conf/conf.d:/etc/mysql/conf.d
- /docker/mysql57/logs:/var/log/mysql
deploy:
mode: global
resources:
limits:
memory: 2048M
docker pull mysql:8.0.32
version: '3'
services:
mysql:
image: mysql:8.0.32
container_name: mysql80
environment:
# 时区上海
TZ: Asia/Shanghai
# root 密码
MYSQL_ROOT_PASSWORD: root
ports:
- "3307:3306"
volumes:
# 数据挂载
- /docker/mysql80/data/:/var/lib/mysql/
# 配置挂载
- /docker/mysql80/conf/:/etc/mysql/conf.d/
# 日志挂载
- /docker/mysql80/logs:/var/log/mysql
command:
# 将mysql8.0默认密码策略 修改为 原先 策略 (mysql8.0对其默认策略做了更改 会导致密码无法匹配)
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
privileged: true
network_mode: "host"
#docker-compose 后期后台启动
docker-compse up -d
#docker-compose 容器停止
docker-compse down
#进入容器内部
docker exec -it [容器Id前三位/容器名称] /bin/bash
# 获取容器ip
docker inspect [容器Id前三位/容器名称]
#退出容器
exit
1、如果yaml或者yml文件改为非,使用 docker-compose up -d会失效,必须使用如下命令:
#默认名称为docker-compose.yaml的情况 启动命令
docker-compose up -d
#名称不为docker-compose.yaml的情况 启动
docker-compose -f [新yaml或yml名称] up -d
docker-compose -f /docker/mysql57/yaml/docker-compose57.yaml up -d
docker-compose -f /docker/mysql80/yaml/docker-compose80.yaml up -d
https://blog.csdn.net/qq_28597013/article/details/121864586
https://gitee.com/dromara/RuoYi-Vue-Plus/blob/5.X/script/docker/docker-compose.yml