|
| 1 | +--- |
| 2 | +title: "Portable App Distribution for Docker" |
| 3 | +url: /developerportal/deploy/docker-deploy-pad/ |
| 4 | +weight: 20 |
| 5 | +description: "Describes how to deploy using a Docker image by using Portable App Distribution." |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +This guide provides a walkthrough for deploying your Mendix application using [Portable App Distribution](/developerportal/deploy/portable-app-distribution-deploy/) with Docker. This approach is particularly useful for containerized environments, and can significantly ease your CI/CD setup. |
| 11 | + |
| 12 | +{{% alert color="info" %}} |
| 13 | +This document is not an official Mendix implementation, or a substitute for recommended production deployment strategies. For more features, such as app management or governance, we suggest using [Mendix on Kubernetes](/developerportal/deploy/private-cloud/) or [Mendix on Azure](/developerportal/deploy/mendix-on-azure/), which offer a structured, tested experience with cloud infrastructure. |
| 14 | + |
| 15 | +For information about the scope of support, see [Support for Different Deployment Strategies](/support/deployment-strategy-support/). |
| 16 | +{{% /alert %}} |
| 17 | + |
| 18 | +## Benefits of Portable App Distribution |
| 19 | + |
| 20 | +Portable App Distribution revolutionizes the way in which Mendix applications are packaged and delivered. This innovative approach bundles your application code with all its necessary dependencies into a single, self-contained, and runnable artifact. This greatly simplifies the deployment of Mendix applications, whether you are targeting on-premise infrastructure or modern containerized environments like Docker, making the entire process more efficient and seamless. |
| 21 | + |
| 22 | +The ability to generate a Portable App Distribution with a single build command means that creating a Docker-ready artifact becomes a streamlined process, making the overall integration into existing Docker-based CI/CD pipelines more efficient and less prone to errors. |
| 23 | + |
| 24 | +Portable App Distribution offers a more agile, user-centric, and efficient deployment ecosystem, empowering customers with greater control over their Docker deployments and simplifying the internal deployment processes. |
| 25 | + |
| 26 | +## Deploying an App with Portable App Distribution |
| 27 | + |
| 28 | +The Portable App Distribution feature in Mendix Studio Pro provides you with the necessary application files to build a Docker image. It packages your Mendix application as a self-contained distribution, ready for integration into your Docker environment. |
| 29 | + |
| 30 | +To deploy your app to Docker, perform the following steps: |
| 31 | + |
| 32 | +1. Generate the application files. For more information, see [Portable App Distribution](/developerportal/deploy/portable-app-distribution-deploy/). |
| 33 | + |
| 34 | + These files are the core of your Mendix application and are ready to be included in a Docker image. |
| 35 | + |
| 36 | + The following is an example *Dockerfile* that incorporates them. You must create this Dockerfile yourself and place it alongside the application files generated by the Portable App Distribution. The `COPY` commands in the example below assumes that the `app`, `bin`, `etc`, and `lib` directories are in the same location as your Dockerfile. |
| 37 | + |
| 38 | + ```text |
| 39 | + # This file provides an example on how to start the runtime in Docker. |
| 40 | + # It is based on the configuration named Default. |
| 41 | +
|
| 42 | + FROM eclipse-temurin:21-jdk |
| 43 | +
|
| 44 | + # Set working directory |
| 45 | + WORKDIR /mendix |
| 46 | +
|
| 47 | + # Copy Mendix app files into the image |
| 48 | + COPY ./app ./app |
| 49 | + COPY ./bin ./bin |
| 50 | + COPY ./etc ./etc |
| 51 | + COPY ./lib ./lib |
| 52 | +
|
| 53 | + # Environment variables (optional) |
| 54 | + ENV MX_LOG_LEVEL=info |
| 55 | + ENV M2EE_ADMIN_PASS=${M2EE_ADMIN_PASS} |
| 56 | +
|
| 57 | + # Expose ports |
| 58 | + EXPOSE 8090 |
| 59 | + EXPOSE 8080 |
| 60 | +
|
| 61 | + # Start command |
| 62 | + CMD ["./bin/start", "etc/Default"] |
| 63 | + ``` |
| 64 | +
|
| 65 | +2. Build the Docker image by running a command like the following: `docker build -t mx/project:latest -f build/docker/Dockerfile`, where: |
| 66 | +
|
| 67 | + * `-t mx/project:latest` - Tags your image as `mx/project` with the label `latest`. You can customize this to your project's name and version. |
| 68 | +
|
| 69 | + * `-f build/docker/Dockerfile` - Specifies the path to your Dockerfile. |
| 70 | +
|
| 71 | +3. Start your Mendix application in a Docker container by running a command like the following: `docker run --rm -it -p 8080:8080 -e M2EE_ADMIN_PASS=<your password> mx/project:latest`, where: |
| 72 | +
|
| 73 | + * `--rm` - Automatically removes the container when it exits. |
| 74 | + * `-it` - Runs the container in interactive mode and allocates a pseudo-TTY. |
| 75 | + * `-p 8080:8080` - Maps port 8080 on your host machine to port 8080 inside the container, allowing you to access your app. |
| 76 | + * `-e M2EE_ADMIN_PASS=<yourPassword>` - Ensure that you set your admin password here. |
| 77 | + * `mx/project:latest` - Refers to the image that you built. |
| 78 | +
|
| 79 | +You can view your running Mendix application at `localhost:8080`. To stop the application, press **Ctrl-C** in your terminal. |
| 80 | +
|
| 81 | +## Docker Compose for Multi-Container Setups |
| 82 | +
|
| 83 | +For more complex setups involving multiple Docker containers, or for simpler local testing purposes, you can use Docker Compose. It allows you to define and run multi-container Docker applications. |
| 84 | +
|
| 85 | +The following is an example of a *docker-compose.yaml* file that sets up your Mendix application with an HSQLDB for local testing. This example assumes you have the Portable App Distribution files (`app`, `bin`, `etc`, `lib`) in a parent directory relative to your *docker-compose.yaml* file. |
| 86 | +
|
| 87 | +```yaml |
| 88 | +# This file provides an example on how to start the runtime with HSQLDB. |
| 89 | +# This setup is intended for local testing only. |
| 90 | +# It is based on the configuration named Default. |
| 91 | +
|
| 92 | +services: |
| 93 | + mendix-app: |
| 94 | + image: eclipse-temurin:21-jdk |
| 95 | + container_name: mendix-app |
| 96 | + working_dir: /mendix |
| 97 | + volumes: |
| 98 | + - ../app:/mendix/app |
| 99 | + - ../bin:/mendix/bin |
| 100 | + - ../etc:/mendix/etc |
| 101 | + - ../lib:/mendix/lib |
| 102 | + environment: |
| 103 | + - MX_LOG_LEVEL=info |
| 104 | + - M2EE_ADMIN_PASS=${M2EE_ADMIN_PASS} |
| 105 | + ports: |
| 106 | + - "8090:8090" |
| 107 | + - "8080:8080" |
| 108 | + command: ["./bin/start", "etc/Default"] |
| 109 | +``` |
| 110 | + |
| 111 | +### Running with Docker Compose |
| 112 | + |
| 113 | +To use this Docker Compose configuration, perform the following steps: |
| 114 | + |
| 115 | +1. Set your admin port password in the **M2EE_ADMIN_PASS** variable within your environment, or directly in the *docker-compose.yaml* file. |
| 116 | +2. Navigate to the directory containing your *docker-compose.yaml* file |
| 117 | +3. Run a command like the following: `docker compose -f docker_compose/Default.yaml up` |
| 118 | + |
| 119 | +This example assumes that your configuration is named Default. |
0 commit comments