Skip to content

Instantly share code, notes, and snippets.

@valentin2105
Last active March 19, 2021 09:09
Show Gist options
  • Save valentin2105/9c6abe0acc9a05ca0fa3abbf830d80a6 to your computer and use it in GitHub Desktop.
Save valentin2105/9c6abe0acc9a05ca0fa3abbf830d80a6 to your computer and use it in GitHub Desktop.
High-Available Wordpress PoC on Docker Swarm 1.12.x with MariaDB Galera cluster.
#! /bin/bash
wordpressPath=/srv/wp01
wordpressName=wordpress01
wordpressPwd=pAssw0rd
wordpressUrl=wordpress01.example.com
##################################
mkdir -p "$wordpressPath"/db
mkdir -p "$wordpressPath"/www
docker network create --driver=overlay $wordpressName
docker service create --name "$wordpressName"-db-cluster \
--network $wordpressName \
--replicas=1 \
--env MYSQL_ROOT_PASSWORD=$wordpressPwd \
--env MYSQL_DATABASE=wordpress \
--env DB_SERVICE_NAME="$wordpressName"-db-cluster \
--mount type=bind,source="$wordpressPath"/db,target=/data \
valentinnc/mariadb-galera:10.1
sleep 2
docker service create --name wordpress01 \
--replicas 1 \
--network $wordpressName \
--network traefik-net \
--label traefik.port=80 \
--label traefik.frontend.rule=Host:"$wordpressUrl" \
-e WORDPRESS_DB_HOST="$wordpressName"-db-cluster \
-e WORDPRESS_DB_PASSWORD=$wordpressPwd \
-e WORDPRESS_DB_USER=root \
--mount type=bind,source="$wordpressPath"/www,target=/var/www/html \
wordpress:latest
echo
echo "You can scall up services with theses commands :"
echo
echo "docker service scale "$wordpressName"-db-cluster=3"
echo "docker service scale "$wordpressName"=3"
docker network create --driver=overlay traefik-net
docker service create \
--name traefik \
--publish 80:80 --publish 443:443 --publish 8080:8080 \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--mount type=bind,source=/srv/traefik/traefik.toml,target=/etc/traefik/traefik.toml \
--network traefik-net \
--mode global \
traefik:v1.1.0-rc1 \
--docker \
--docker.swarmmode \
--docker.domain=example.com \
--docker.watch \
--logLevel=DEBUG \
--web
################################################################
# Web configuration backend
################################################################
[web]
address = ":8080"
################################################################
# Docker configuration backend
################################################################
[docker]
endpoint = "unix:///var/run/docker.sock"
watch = true
swarmmode = true
@valentin2105
Copy link
Author

valentin2105 commented Nov 8, 2016

This configuration provide a High-available Wordpress using MariaDB Galera Cluster.

  • It work from scratch in a singleNode Swarm cluster.
  • If you have multi-nodes, you need to sync the $wordpressPath folder between hosts using GlusterFS or Btsync for example.
  • You can scale-up App and DB containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment