Drupal is an opensource platform for web content management and for building websites and much more web related digital experiences.
Here, I am gonna show you how to deploy drupal service. Let’s dig in.
Stack!

I am not gonna go in depth of it, because a quick overview will be fine. Stack is a place where one can deploy docker-compose file on docker swarm cluster as a service.
Stack manages all your containers and their replicas deployed as a service on swarm cluster and it also manages your networks and volumes defined in compose or stack file. It supports YAML file format same as docker-compose.yml …this makes us feel native towards using stack.
Here is my repository on GitHub: https://github.com/mykg/drupal-stack-deploy
Now let’s have a look at stack.yml file at github: https://github.com/mykg/drupal-stack-deploy/blob/master/stack.yml
Quick Explanation of stack.yml
- version: ‘3’ specifies the compose version we want you use
- services: under this block we define services to deploy
- dbos: is the name of the service
- image: which image you want to use
- volumes(under services): which volume to attach with which directory of that container
- environment: specify the environment variables
- deploy: it handles the variables under deploy condition
- replicas: we can define number of replicas to be created of that container
- restart: always will keep container running
- restart_policy: i have defined if any container falls down it will create another on failure
Under drupal_os: everything is kind of same except:
- depends_on: here I have specified the container name that it depends on (same as –link option doing manually)
- ports: here I exposed the ports for drupal to access it from our webpage
- At last of we have specified the volumes to be created under volumes:
If you want to look more into compose file formatting: https://docs.docker.com/compose/
For environments variables: https://docs.docker.com/compose/environment-variables/
To checkout more environment variables, volumes and database connections available for drupal: https://hub.docker.com/_/drupal
My Environment
- On bare metal I have Windows 10 pro
- And 3 RHEL 7.5 vms running on vmware
- Docker daemon running on all 3 vms
- 1 is manager node and other 2 as worker nodes
Swarm init
# systemctl start docker
this will start docker daemon
# systemctl enable docker
this will enable service of docker
run these commands in all 3 vms
# docker swarm init
this will initialize the swarm and make that vm a manager node, a join token will appear, copy this and paste in other 2 vms and then run it.
This will make those 2 vms as worker node
# docker node ls
to check on nodes available and their status
To check on more about swarm cluster visit: https://mynk.home.blog/2020/01/05/how-to-create-a-3-node-swarm-cluster-using-docker-machine/
Deployment
Clone that repository or copy the code from stack.yml: https://github.com/mykg/drupal-stack-deploy
# docker stack deploy -c stack.yml DRUPAL
this will deploy the stack on swarm
# docker service ls
lists the number of services available, it will show 2 services, one of drupal and other of mysql
# docker service ps <service_name>
this will let you know about the service and its replicas and on which node it is running
To access drupal visit: http://localhost:8082 or http://ip-of-any-node:8082 it will look like this:-

Under set up databases… select these as we are running mysql and we have created database named drupal_db and name of that container is the host so that is dbos

Verifying things
We almost did everything, let’s test something… we know that on failure of any container it should be deployed again soon… let’s try that…
# docker container ls
this will show containers running on that vm
# docker container rm -f <container-id>
this will remove that container forcefully
# docker service ls
run this above command on manager node and you will see a replica of container must be reduced to 1
Now we removed a container from the service ….
# docker container ls
do this until you see that container again
# docker service ls
you can also check on manager node that replica again restored
This is the beauty of docker swarm cluster or any other container clustering tool.
If you want to check the mysql storing tables or not then:
# mysql -h <ip-of-mysql-container> -u mayank -predhat
In my case user name is mayank and password is redhat....after that choose your database and you can see your tables
I have also created same cluster for wordpress you can check that out here: https://github.com/mykg/wordpress-stack-deploy
Please give me review or you can leave a comment below.
Thanks.