docker查看并创建本地公共网络
# 根据需要选择命令执行,如果 deploy 网络已创建,可忽略
docker network ls
docker network inspect deploy
docker netwok rm deploy
docker network create --driver=bridge --subnet=172.10.0.0/16 deploy
通过docker-compose部署管理应用
# 环境变量
cat << EOF> .env
MYSQL_ROOT_PASSWORD=mysql
MYSQL_USER=canal
MYSQL_PASSWORD=canal
MYSQL_DATABASE=test
EOF
# docker-compose配置文件 docker-compose.yaml
cat << EOF> docker-compose-mysql.yaml
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql
restart: always
networks:
deploy:
ipv4_address: 172.10.0.4
aliases:
- mysql
ports:
- "13306:3306"
env_file:
- .env
environment:
- TZ=Asia/Shanghai
volumes:
- ./db:/var/lib/mysql:rw
- ./src/config/mysqld.cnf:/etc/my.cnf:ro
tty: true
networks:
deploy:
external: true
EOF
# mysql自定义配置
# src/config/mysqld.cnf
mkdir -p src/config
cat << EOF> src/config/mysqld.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
max_allowed_packet=500M
[mysqld]
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password
ft_min_word_len=2
lower_case_table_names=1
default_time_zone=+8:00
max_connections = 512
tmp_table_size = 10240M
max_heap_table_size = 10240M
# 开启binlog,这里按需配置
log-bin=mysql-bin
binlog-format=ROW # 选择ROW模式
server_id=1 # 配置MySQL replaction需要定义,不要和Canal的slaveId重复
EOF
# docker-compose管理
docker-compose -f docker-compose-mysql.yaml up -d # 启动
docker-compose -f docker-compose-mysql.yaml down -v # 停止并移除实例
# 连接mysql,然后开始你的表演
docker exec -it mysql mysql -uroot -p
# 或者通过宿主机IP连接,也可以通过客户端工具连接
mysql -h 127.0.0.1 -P 13306 -uroot -p
更多docker应用,请参考我的Github:
https://github.com/darebeat/docker-center/tree/master/deploy