新建目录
- mkdir -p /data/docker/mysql/data
- mkdir -p /data/docker/mysql/logs
- mkdir -p /data/docker/mysql/conf
给权限
chmod -R 777 /data/docker/mysql
到目录
cd /data/docker/mysql
新建docker-compose.yml文件
vi docker-compose.yml
复制配置文件内容,粘贴到docker-comose.yml中
- version: '3.3'
-
- services:
-
- mysql-db:
- # 指定容器的名称
- container_name: mysql
- # 指定镜像和版本
- image: mysql:5.7
- ports:
- - "3306:3306"
- restart: always
- # 容器日志大小配置
- logging:
- driver: 'json-file'
- options:
- max-size: '1g'
- environment:
- # 配置root密码
- MYSQL_ROOT_PASSWORD: root
- #时区
- TZ: Asia/Shanghai
- volumes:
- # 挂载数据目录
- - "/data/docker/mysql/data:/var/lib/mysql"
- # 挂载配置文件目录
- - "/data/docker/mysql/config:/etc/mysql/conf.d"
- - "/data/docker/mysql/logs:/var/log/mysql"
修改配置
- cd /usr/local/mysql/conf
- vim my.cnf
- [client]
- default_character_set=utf8
- [mysqld]
- collation_server=utf8_general_ci
- character_set_server=utf8
启动容器
docker-compose up -d