version: '3' services: # 主从mysql配置 mysql-master: image: mysql:8.0.24 restart: always container_name: mysql-master environment: MYSQL_ROOT_PASSWORD: "root" command: [ '--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', '--max_allowed_packet=128M', '--server-id=1', '--log-bin=xbd-master-bin', '--binlog-ignore-db=mysql', '--binlog_cache_size=256M', '--binlog_format=mixed', '--lower_case_table_names=1', '--character-set-server=utf8', '--collation-server=utf8_general_ci', '--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'] ports: - "3306:3306" volumes: - ./data/master:/var/lib/mysql #数据 - ./conf/master:/etc/mysql/conf.d #配置 - ./logs/master:/data/mysql/logs #日志 networks: - mysql_default mysql-slaver: image: mysql:8.0.24 restart: always container_name: mysql-slaver volumes: - /var/lib/mysql/xbd-slaver:/var/lib/mysql ports: - "3307:3306" environment: MYSQL_ROOT_PASSWORD: "root" privileged: true # change master to master_host='mysql-master', master_user='root',master_password='root',master_port=3306; # start slave; command: [ '--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', '--max_allowed_packet=128M', '--server-id=2', '--relay_log=xbd-slaver-relay', '--lower_case_table_names=1', '--character-set-server=utf8', '--collation-server=utf8_general_ci', '--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'] volumes: - ./data/slaver:/var/lib/mysql #数据 - ./conf/slaver:/etc/mysql/conf.d #配置 - ./logs/slaver:/data/mysql/logs #日志 networks: - mysql_default networks: mysql_default: external: true
标签:compose,NO,--,slaver,server,master,mysql,docker From: https://www.cnblogs.com/qianxiaoPro/p/16985956.html