Docker Compose to connect Camunda BPM and MySQL containers
So basically, I had a task in my project for connecting my Camunda Application to an External Database instead of the inbuilt H2-Database. Since I was using Camunda docker container for my project, I came up with a solution to use MySQL docker container and connect it to my Camunda container.
Now, in this scenario we will require multiple containers to be running and to run them we need to execute individual commands every time for each container.
To escape from typing in the commands again and again for every container, Docker Compose comes to the rescue.
Docker Compose is a tool for defining and running multi-container Docker applications. It creates development environments using a special file. The file is named as “docker-compose.yml“. It’s a YAML file. YAML is basically a human readable data serialization file. This file will tell docker what images to use for the container, what ports to use, which folders to mount, how to set up the environment variables and much more.
I am using Docker Toolbox for Windows, for doing this POC.
You can Install Docker Toolbox for Windows by reading my other Blog, if required. Click here
Moving further, below are the steps that will help connect Camunda and MySQL using docker-compose.
1. Check version of your Docker and Docker Compose, using below commands:
$ docker -v
$ docker-compose -v

2. Pull the docker images for Camunda and MySQL from Docker Hub, using below command respectively:
$ docker pull camunda/camunda-bpm-platform:latest
$ docker pull mysql:latest
3. After pulling the image, check for the images and make sure no container is running for those 2 images:
$ docker images
$ docker ps

4. Now make a directory for keeping your docker-compose.yml file and navigate into that directory.
$ mkdir docker_compose
$ cd docker_compose/

5. Create a docker-compose.yml file as below:

So basically,
version -> The version of your docker-compose.yml file depends on your docker version (you can check compatibility for docker-compose.yml version here)
services ->mysql-db & camunda are the 2 services which will be used to setup our environment using the docker-compose.yml file.
image -> It is the name of the image that will be used by docker to run the respective containers.
container_name ->It is used to give name to the docker containers when they will be made.
ports -> It’s format is as “exposed_port:container_port”.
environment -> It is used to set the environment variables in the containers for respective applications, every time we make container from image via the docker_compose.yml file.
depends_on -> Here we will specify the service name (mysql-db) on which the current service (camunda) depends upon to run. So, when mysql container is up then it will run the camunda container.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Note: Camunda has its in-built database i.e. H2 Database.
For making Camunda to connect and use an external DB, for example MySQL.
We need to make changes to the Environment variables in Camunda container using the docker-compose.yml file as shown below:

com.mysql.jdbc.Driver This driver will be used by Camunda to connect to the MySQL server instead of H2Server.
mysql-db is the service name for MySQL server.
3306 is the mysql server port number.
camunda_db is the database name where it will make all the tables/schema, etc.
root is the username and password for the MySQL server.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
6. Copy the docker-compose.yml file to the docker_compose directory you created and then view the file using below command.
$ cat docker-compose.yml

7. Now execute the docker-compose.yml file for running the multiple containers via below command
$ docker-compose up -d

Check whether both the containers are running or not.
$ docker ps

8. For confirming the Camunda application is up. Check using the URL as shown below:

9. For confirming that Camunda is connected to the MySQL server, we will login into the MySQL server via MySQL Workbench and check whether the tables of Camunda got created in the camunda_db database or not.
port will be 8050: mysql container exposed port
username: root
password: root

We can see that the tables are successfully created and Camunda is now using an External Database i.e. MySQL DB using Docker Compose.

