Skip to content

Instantly share code, notes, and snippets.

@sGerli
Created September 4, 2019 23:08
Show Gist options
  • Save sGerli/6dd204e877583be29148357eb6672626 to your computer and use it in GitHub Desktop.
Save sGerli/6dd204e877583be29148357eb6672626 to your computer and use it in GitHub Desktop.
MySQL Docker Setup for Replication
version: '3.5'
services:
db-master:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3306:3306'
expose:
# Opens port 3306 on the container
- '3306'
volumes:
- mysql-db-master:/var/lib/mysql
networks:
internal:
aliases:
- mysql
db-1:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3307:3306'
expose:
# Opens port 3306 on the container
- '3306'
volumes:
- mysql-db-1:/var/lib/mysql
- ./my1conf:/etc/mysql/conf.d
networks:
internal:
db-2:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3308:3306'
expose:
# Opens port 3306 on the container
- '3306'
volumes:
- mysql-db-2:/var/lib/mysql
- ./my2conf:/etc/mysql/conf.d
networks:
internal:
volumes:
mysql-db-master:
mysql-db-1:
mysql-db-2:
networks:
internal:
driver: bridge
[mysqld]
server-id=2
replicate-do-db = sakila
replicate-ignore-table=sakila.country
[mysqld]
server-id=3
replicate-do-db = sakila
replicate-ignore-table=sakila.customer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment