Skip to content

Instantly share code, notes, and snippets.

@ball6847
Last active April 14, 2017 08:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ball6847/25ba64edc8de9d2e5ccef1af2f24dfad to your computer and use it in GitHub Desktop.
Save ball6847/25ba64edc8de9d2e5ccef1af2f24dfad to your computer and use it in GitHub Desktop.
Create mariadb cluster using Docker Swarm
#!/bin/sh
# first, create overlay network to make all of your nodes can to talk to each others.
docker network create -d overlay mariadb-network
# then, create primary node, make sure you create the service with only 1 replica
docker service create \
--name mariadb-master \
--replicas 1 \
--mount target=/var/lib/mysql,source=/vol/mariadb-master,type=bind \
--network mariadb-network \
-e MYSQL_ROOT_PASSWORD=rootpassword \
-e MYSQL_REPLICATION_PASSWORD=replicationpassword \
-e MYSQL_CLUSTER_ADDRESS= \
ball6847/mariadb-cluster
# now, your mariadb farm, (set --publish port if needed)
docker service create \
--name mariadb \
--replicas 1 \
--mount target=/var/lib/mysql,source=/vol/mariadb,type=bind \
--network mariadb-network \
-e MYSQL_ROOT_PASSWORD=rootpassword \
-e MYSQL_REPLICATION_PASSWORD=replicationpassword \
-e MYSQL_CLUSTER_ADDRESS=mariadb-master \
ball6847/mariadb-cluster
# finally, you can scale your farm as you wish, but make sure it run one container per node.
docker service scale mariadb=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment