Containerize your Mendix Application with Docker
You worked hard and your web application developed using Mendix is ready to be shipped! If you are using the Mendix Cloud, just hit the Publish button in the Studio Pro IDE and your application is “on the air”. But, what if you intend to use cloud services like AWS, Azure, or GCP? How can you deliver your application to your customers? The answer is using technologies like Docker and Kubernetes.
Please see the updated information regarding the procedure described in this article (section named: Update! Studio Pro 10.12 [2024/07/16] — Windows 11) concerning the newest Studio Pro version 10.12
Scenario
Once again our scenario is identical to the previous article: a simple application that takes two numbers and calculates their sum. But this time the goal is to pack all the resources required to run the application into a container able to be delivered wherever we want! Please follow the procedure below to see how this could be accomplished.
Requirements
To follow this procedure, you will need:
- Docker Engine — This provides the Docker Desktop IDE and the command line tools
- Obviously, your Mendix development environment (Studio Pro, JAVA, Node.JS, GIT, VSCode, …)
- Optionally, a Linux or a Mac machine to prove the portability of Docker with Mendix! In this article, I’ll be using Ubuntu 23.10.
Procedure
- [1] This procedure is done predominantly using the command line. First of all, ensure that your project is protected and committed to a GIT repository. In my case, I’m using Gitlab as a code repository. Spoiler alert: the choice for Gitlab is because the ultimate goal is to have a Mendix application in a CI/CD pipeline, using Cypress as a testing automation platform. So, if you are using a Windows machine, you are ready to go. Else, if you are using Linux or Mac, clone the code from the repository on your machine:
git clone <your project repo>.git
- [2] You will also need to get some files from a repository called mendix/docker-mendix-buildpack. Be aware that the official procedure to use Docker with Mendix is a little different than described here. After this caveat, clone this repository using the command below:
git clone --branch v5.0.3 https://github.com/mendix/docker-mendix-buildpack.git
- [3] Copy
scripts
folder from the Docker Mendix Buildpack to your Mendix project folder structure:
- [4] Copy the
Dockerfile
from the Docker Mendix Buildpack to your Mendix project folder structure. Copy also the filetests/docker-compose-prostgres.yml
. In this case, I’m assuming you also want to use Postgres as your Database. There are scripts for MySQL and SQLServer as well. You will end up with these files and folders:
- [5] Open the docker-mendix-buildpack folder with VS Code and open the file
upgrading-from-v4.md
. It contains two important commands required to generate images that will be used in our Mendix App Container. Read this file for more details.
- [6] In the VS Code terminal, run the two command lines below to generate the
mendix-rootfs:app
and themendix-rootfs:builder
images:
docker build -t mendix-rootfs:app -f rootfs-app.dockerfile .
docker build -t mendix-rootfs:builder -f rootfs-builder.dockerfile .
- The
builder
image contains packages required to build an app; theapp
image contains a reduced package set, containing only packages required to run a Mendix app. - [7] If everything works as expected, we will have the two images generated, as shown in Docker Desktop:
- [8] Now, back to our Mendix project, in the VS Code Terminal, run the command below to generate the app image:
docker build --build-arg BUILD_PATH=. -t vstram/mx_test_app:1.0 .
- ATTENTION: Notice that I’m using my Docker user name
vstram
as part of the image name. You should use your own name:johndoe/mx_test_app:1.0
- [9] Besides Docker Desktop, we can also use the command line
docker images
to inspect the images:
- [10] Edit the 5th line of the file
docker-compose-postgres.yml
copied in step 4 to change the application image tovstram/mx_test_app:1.0
.
- [11] Finally, run the command below to start the database and the server on which your application will run:
docker compose -f ./docker-compose-postgres.yml up
- After some minutes, our application will be available on the URL
http://localhost:8080
:
Update! Studio Pro 10.12 [2024/07/16] — Windows 11
- Originally I tested this procedure on a Linux machine. Today I decided to repeat the same procedure on my Windows 11 machine
- [1] Create a new Blank Web Template v10.12.38909.
- [2] After the project is created, change the Java from 21 to 11 in App/Settings/Runtime/JavaVersion
- [3] In Security, change the Security level to Production.
- [4] This time, I used the docker-medix-build-pack-5.0.4.
- [5] Edit the file
docker-compose-postgres.yml
, line 13, the ADMIN_PASSWORD to comply with the requirements (12 chars and digits, mixed case, symbols)
- The remaining of the procedure is still valid.
Conclusions
It’s amazing how Mendix works easily with Docker!! The files in the Docker Mendix Buildpack are very useful. I firmly believe that all Mendix developers should use Docker more intensively during code development. We can easily change the DB provider, the DB version, testing the “dockerized” application with different operational systems. If you plan to use Microservices with Mendix, it’s easier to spin up all the services with Docker and Kubernetes. You can test all the implementation locally, using Minikube and, if works fine locally, get confident that it will also work fine in production.
Besides these advantages, Docker was useful to use together with GitLab as our CI/CD platform, defining a pipeline that includes the application image generation, e2e tests with Cypress and also sending a notification with the status of the pipeline execution via Slack. This will be the subject of the next article to be published here on Medium!