安装环境
- Docker
- Docker-Compose
- MySql 5.7+
查询镜像
1.进入DockerHub,搜索Mysql
2.查看并选择支持的tag,演示环境选择5.7.36
docker run
启动命令
docker run --name csp-mysql -p 3306:3306 -v /opt/mysql/conf:/etc/mysql/conf.d -v /opt/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --restart=always -d mysql:5.7.36
执行命令
先读取本地是否有
mysql:5.7.36
的镜像,如果没有则从远程仓库拉取
查看容器
docker ps
docker-compose
目录结构
mysql57/
docker-compose.yml
- conf
my.cnf
- data
编写配置文件
cd /opt/mysql57/conf
vim my.cnf
[mysqld]
character-set-server=utf8mb4
default-time-zone='+8:00'
collation-server=utf8mb4_bin
default-storage-engine=INNODB
max_allowed_packet=512M
innodb_log_file_size=2GB
transaction-isolation=READ-COMMITTED
binlog_format=row
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
编写docker-compose
cd /opt/mysql57
vim docker-compose.yml
version: '3'
services:
mysql-57:
image: mysql:5.7.36
container_name: mysql-57
restart: always
ports:
- "3357:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
volumes:
- ./conf/my.cnf:/etc/my.cnf
- ./data:/var/lib/mysql
启动
docker-compile build
docker-compile up