Deploying Flowable in a Docker Container and MySQL (Part 2)

Deploying Flowable in a Docker Container and MySQL (Part 2)

This is the second part of our “Deploying Flowable in a Docker Container and MySQL” series. In this post, you will learn how to deploy Flowable’s war files in a container running Tomcat, and connecting to another container running use MySQL database.

What you’ll need

  • About 30 minutes
  • Docker Desktop for you operating system already installed. For this tutorial, we used Docker Desktop for Windows. You can download it from here.
  • Download Flowable war files. You can download them from here. We need a fresh copy without any modification.
  • Download MySQL Connector/J. You can download it from here.

Introduction

In this article, you will learn how to deploy Flowable’s war file in a dockerized Tomcat environment and connecting to a container running MySQL. The main difference with the first part of this series, is that we will not modify the war files, instead, we will pass the database configuration properties as environment variables.

If you would like to know how to compile from scratch Flowable’s source code so that is uses MySQL as default database source, and afterward deploy it in a dockerized environment, please have a look at our post Run Flowable BPM using Docker and MySQL.

So let’s get started!!

Folder Structure

This is the folder structure that we will be using for this tutorial:

root 
  |- flowable-docker 
       |- wars 
           |- flowable-admin.war 
           |- flowable-idm.war 
           |- flowable-modeler.war 
           |- flowable-task.war 
       |- tomcat-users-xml 
       |- mysql-connector-java-8.0.20.jar
       |- Dockerfile 
       |- docker-compose.xml

Creating the Tomcat User file

So that we can access the management app’s web page that Tomcat offers, we can add some user with valid credentials and roles. Create the following file and called tomcat-users.xml under flowable-docker folder:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
  <user 
       username="tomcat" 
       password="tomcat"
       roles="tomcat,standard,manager-gui,manager-status,manager-script,manager-jmx"
  />
</tomcat-users>

Here, we have created a user called tomcat, with tomcat as password, and assigned the following roles: tomcat,standard,manager-gui,manager-status,manager-script,manager-jmx.

Creating the Dockerfile

Docker has a simple file format called Dockerfile, which uses to specify the _layers_ of an image. Having said this, let’s go ahead and create a Dockerfile using your favorite text editor:

# Use an official Tomcat runtime as a parent image 
FROM tomcat:8.0-jre8 

ENV DIRPATH /usr/local/tomcat 

# copy MySQL Connector/J to Tomcat's /lib folder
COPY ./mysql-connector-java-8.0.20.jar $DIRPATH/lib

# Copy Tomcat users into the container at /conf 
COPY ./tomcat-users.xml $DIRPATH/conf 

# Copy flowable-admin war file into the container at /webapps 
COPY ./wars/flowable-admin.war $DIRPATH/webapps 

# Copy flowable-idm war file into the container at /webapps 
COPY ./wars/flowable-idm.war $DIRPATH/webapps 

# Copy flowable-modeler war file into the container at /webapps 
COPY ./wars/flowable-modeler.war $DIRPATH/webapps 

# Copy flowable-task war file into the container at /webapps 
COPY ./wars/flowable-task.war $DIRPATH/webapps 

# Make port 8080 available to the world outside this container 
EXPOSE 8080 

# Run CMD "catalina.sh" when the container launches 
CMD ["catalina.sh", "run"]

This Dockerfile is very simple, but that’s all you need to run a container with Tomcat. This is what the file does:

  1. COPY MySQL Connector/J to Tomcat’s library folder (/user/local/tomcat/lib).
  2. COPY the file tomcat-users.xml to /user/local/tomcat/conf
  3. COPY flowable-admin war file into the container at /webapps
  4. COPY flowable-idm war file into the container at /webapps
  5. COPY flowable-modeler war file into the container at /webapps
  6. COPY flowable-task war file into the container at /webapps
  7. Make port 8080 available to the world outside this container
  8. Run CMD catalina.sh when the container launches

Creating docker-compose.yml file

In the file, we specify container for MySQL (mysql-db), and Tomcat container (tomcat). Notice that we have included adminer database manager, so that we can access the database from a web interface.

version: '3.7'
services:
  mysql-db:
    image: mysql:5.7.26
    container_name: flowable-mysql-mysql-5.7.26
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: flowable
      MYSQL_USER: flowable
      MYSQL_PASSWORD: flowable
      MYSQL_DATABASE: flowable
    ports:
      - "3306:3306"
    networks:
      - flowable-mysql
      
  adminer:
    image: adminer
    restart: always
    ports:
      - 18080:8080
    networks:
      - flowable-mysql

  tomcat:
    build: .
    image: tomcat:8.0-jre8
    ports:
      - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
    environment:
      - SPRING_DATASOURCE_DRIVER-CLASS-NAME=com.mysql.cj.jdbc.Driver
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql-db:3306/flowable?autoReconnect=true
    depends_on:
      - mysql-db # This service depends on mysql. Start that first.
    restart: always
    networks:
      - flowable-mysql

# Networks to be created to facilitate communication between containers
networks:
  flowable-mysql:

# Volumes
volumes:
    db_data: {}

So that the containers can communicate between them, we have created a network that we have called flowable-mysql.

Let’s have a quick look at MysQL container’s configuration. When you start the mysql image, you can adjust the configuration of the MySQL instance by passing one or more environment variables. Do note that none of the variables will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.

With the environment variables that we are configuring, according to the official documentation, the database flowable will automatically be created, and the users root and flowable will be granted all privileges.

Now, the main difference in the docker-compose.yml file in comparison with the first part of this series, is that we are passing the database connection configuration using environment variables. And since it is an environment variable, and all the war files use it, with just a few lines, we have made the same changes to all of Flowable’s war files.

Note that in the datasource url, we have used the name of the MySQL container as address.

Start the containers

Run the following command and build the images:

$ docker-compose build
mysql-db uses an image, skipping
adminer uses an image, skipping
Building tomcat
Step 1/10 : FROM tomcat:8.0-jre8
8.0-jre8: Pulling from library/tomcat
05d1a5232b46: Pull complete
5cee356eda6b: Pull complete
89d3385f0fd3: Pull complete
65dd87f6620b: Pull complete
78a183a01190: Pull complete
1a4499c85f97: Pull complete
2c9d39b4bfc1: Pull complete
1b1cec2222c9: Pull complete
fc95b85a81f3: Pull complete
0f3868647539: Pull complete
a3921d755681: Pull complete
350389afc69e: Pull complete
Digest: sha256:268403c3fa09afd9310ced7e83ac021927dca0f04a394a80a0b0220f62e056ed
Status: Downloaded newer image for tomcat:8.0-jre8
 ---> 8391ef8f6ae4
Step 2/10 : ENV DIRPATH /usr/local/tomcat
 ---> Running in 951088cf3379
Removing intermediate container 951088cf3379
 ---> ae39437307fc
Step 3/10 : COPY ./mysql-connector-java-8.0.20.jar $DIRPATH/lib
 ---> 931acc846556
Step 4/10 : COPY ./tomcat-users.xml $DIRPATH/conf
 ---> 19dc781b62bd
Step 5/10 : COPY ./wars/flowable-admin.war $DIRPATH/webapps
 ---> 6e468a040361
Step 6/10 : COPY ./wars/flowable-idm.war $DIRPATH/webapps
 ---> de88df9d2309
Step 7/10 : COPY ./wars/flowable-modeler.war $DIRPATH/webapps
 ---> 18e564f61a12
Step 8/10 : COPY ./wars/flowable-task.war $DIRPATH/webapps
 ---> bd41160d3365
Step 9/10 : EXPOSE 8080
 ---> Running in a5bf538e4122
Removing intermediate container a5bf538e4122
 ---> 9f2f907385f2
Step 10/10 : CMD ["catalina.sh", "run"]
 ---> Running in 9e9e61a9e715
Removing intermediate container 9e9e61a9e715
 ---> 6a1c0ba17f34

Successfully built 6a1c0ba17f34
Successfully tagged tomcat:8.0-jre8

In my case, I already had an image for mysql-db and adminer, so they were skipped. However, the Dockerfile was executed and an images was created with the name tomcat.

Now we just need to start the containers based on these images:

$ docker-compose up -d
Creating network "650-h2_flowable-mysql" with the default driver
Creating volume "650-h2_db_data" with default driver
Pulling mysql-db (mysql:5.7.26)...
5.7.26: Pulling from library/mysql
0a4690c5d889: Pull complete
98aa2fc6cbeb: Pull complete
0777e6eb0e6f: Pull complete
2464189c041c: Pull complete
b45df9dc827d: Pull complete
b42b00086160: Pull complete
bb93567627c7: Pull complete
48acc32b4863: Pull complete
6257d2da4815: Pull complete
1cd5ed3b2653: Pull complete
f4ba7ff24ae9: Pull complete
Digest: sha256:bdee7a98276ccf377d2c00b8ceaa9f65455a9376481467bbcc3d1e6b662dac5d
Status: Downloaded newer image for mysql:5.7.26
Pulling adminer (adminer:)...
latest: Pulling from library/adminer
cbdbe7a5bc2a: Pull complete
1bc86e4cff5f: Pull complete
7be142bd33f5: Pull complete
8132c9e52be3: Pull complete
4751eedb34cf: Pull complete
d415e36b2fed: Pull complete
496b1da48343: Pull complete
c3bde6064779: Pull complete
666d5bf6e1bf: Pull complete
0a1f53fcd241: Pull complete
346a17777f39: Pull complete
5cc2b7995b6d: Pull complete
1a1faca69724: Pull complete
7102c95efcf2: Pull complete
0ad90c826104: Pull complete
Digest: sha256:1a5a60451570d8637f9fc794d9f1ef7ec1f3ed8cba0a9e45a6b6cb887837945b
Status: Downloaded newer image for adminer:latest
Creating 650-h2_adminer_1            ... done
Creating flowable-mysql-mysql-5.7.26 ... done
Creating 650-h2_tomcat_1             ... done

if you list the active container, you should be able to see something like this:

$ docker container ls -a
CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS                      PORTS                               NAMES
ccbbc356e207        tomcat:8.0-jre8                               "catalina.sh run"        35 seconds ago      Up 35 seconds               0.0.0.0:8080->8080/tcp              650_tomcat_1
b375bf990bb4        adminer                                       "entrypoint.sh docke…"   36 seconds ago      Up 35 seconds               0.0.0.0:18080->8080/tcp             650_adminer_1
dd61f326c79a        mysql:5.7.26                                  "docker-entrypoint.s…"   36 seconds ago      Up 35 seconds               0.0.0.0:3306->3306/tcp, 33060/tcp   flowable-mysql-mysql-5.7.26

To see the logs of the tomcat container, type the command docker logs -f CONTAINER_ID.

Let’s see the result

After a few moments, you should be able to access Tomcat’s home page (http://localhost:8080/).

CANCHITO-DEV: Tomcat Main

Now, click on the button <Manager App>. It should prompt you for the credentials that we previously created.

Make sure that Flowable’s apps are up and running.

CANCHITO-DEV: Tomcat Manager App

If they are, you should be able to access Flowable’s apps by visiting the following URLs:

Remember that you will be prompted to log in by Flowable’s IDM. Enter admin as user and test as password.

Stopping the container

When you are done working with Flowable’s apps, you can stop and remove Docker containers, images, networks and volumes.

$ docker-compose down -v
Stopping 650_tomcat_1                ... done
Stopping 650_adminer_1               ... done
Stopping flowable-mysql-mysql-5.7.26 ... done
Removing 650_tomcat_1                ... done
Removing 650_adminer_1               ... done
Removing flowable-mysql-mysql-5.7.26 ... done
Removing network 650_flowable-mysql
Removing volume 650_db_data

Summary

In this post, we have shown how to deploy Flowable’s war files in a dockerized environment and using a MySQL database. We hope that, even though this was a very basic introduction, you understood how to use and configure them. We will try to go deeper into Flowable in upcoming posts.

Please feel free to contact us. We will gladly response to any doubt or question you might have.

If you like it, read our first part here.

0 0 votes
Article Rating
Subscribe
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback
3 years ago

[…] If you like it, read our second part here. […]