In the last few years, I’ve got a few customers asking me if the Mule Runtime can be containerized. The answer is yes, and in this post I wanted to prove it. So, in this post we will run a small proof of concept. We will create a Docker image of the Mule runtime and deploy a container from that image. This way we will see, first hand, that Mule can be containerized.
In the image we will build, we will try to replicate all the steps that we followed in an installation of a Standalone runtime on an Ubuntu Server. We’ll use this post as a reference - How to install the Mule Runtime on Ubuntu ServerThe goal of this post is not to create an optimal image.
Prepare the Mule Runtime Files
First, we need to prepare the files to build the image. For that, choose a folder in your laptop (or docker host). That will be our docker image folder.Next, we need to get the Mule Runtime binaries. Go to the Official Mulesoft Site and download the binaries for Linux of the last mule runtime version (at the time of writing this post, that’s mule 4.8.0).
Copy that zip file into our docker image folder.
Create Dockerfile
A Dockerfile is a text file that contains the series of instructions we need to create a Docker image. Each instruction in the Dockerfile defines a step in building the image, such as specifying a base image, copying files, running commands, setting environment variables, or exposing ports. Docker reads the Dockerfile and executes its instructions to generate an image, which can then be used to create and run containers.For that, create a file called
dockerfile
in our docker image folder. For our Mule Runtime image this is the Dockerfile we’ve defined:FROM ubuntu:24.04
# Create installation folder
RUN mkdir /mule
# Install Java JDK and tools
RUN apt-get update && apt-get install -y openjdk-17-jdk
RUN apt-get install unzip
# Copy Mule Runtime files into the container and extract the files
ADD mule-ee-distribution-standalone-4.8.0.zip /mule
RUN unzip /mule/mule-ee-distribution-standalone-4.8.0.zip -d /mule && \
rm /mule/mule-ee-distribution-standalone-4.8.0.zip
# Set environment variables
ENV MULE_HOME=/mule/mule-enterprise-standalone-4.8.0
ENV PATH=$MULE_HOME/bin:$PATH
# Set work directory
WORKDIR $MULE_HOME
# Define Volumes
VOLUME $MULE_HOME/apps
VOLUME $MULE_HOME/conf
VOLUME $MULE_HOME/domains
VOLUME $MULE_HOME/logs
# Expose HTTP ports for Mule Apps
EXPOSE 8081-8091
# Expose ports for the Mule Cluster
EXPOSE 5701-5703
EXPOSE 54327
# Expose ports for the Mule Agent
EXPOSE 9999
EXPOSE 9997
# Run the Mule
CMD ["mule"]
Let’s break it down:
1. Base Image
FROM ubuntu:24.04
2. Create Installation folder
RUN mkdir /mule
3. Install Java JDK and tools
RUN apt-get update && apt-get install -y openjdk-17-jdk
RUN apt-get install unzip
The binaries of the mule will be compressed with zip, that’s why we need to install unzip.
4. Copy Mule Runtime files into the container and extract the files
ADD mule-ee-distribution-standalone-4.8.0.zip /mule
RUN unzip /mule/mule-ee-distribution-standalone-4.8.0.zip -d /mule && \
rm /mule/mule-ee-distribution-standalone-4.8.0.zip
Make sure the zip file is located in our docker image file, otherwise the image won’t be able to copy the binaries.
5. Set environment variables
ENV MULE_HOME=/mule/mule-enterprise-standalone-4.8.0
ENV PATH=$MULE_HOME/bin:$PATH
6. Set work directory
WORKDIR $MULE_HOME
7. Define Volumes
VOLUME $MULE_HOME/apps
VOLUME $MULE_HOME/conf
VOLUME $MULE_HOME/domains
VOLUME $MULE_HOME/logs
- apps - All the apps deployed to the mule runtime using this image will be stored here
- conf - Location for all configuration files, cluster files, object stores...
- domains - Configuration of the domain projects
- logs - Location for the logs of all of our apps and the runtime
8. Expose Ports
EXPOSE 8081-8091
EXPOSE 5701-5703
EXPOSE 54327
EXPOSE 9999
EXPOSE 9997
- 8081 - 8091: The range could be different. These are the ports we reserve for the Mule Apps
- 5701-5703, 54327: These are the communication ports between nodes in a Mule cluster, in case we wanted to create a cluster with runtimes in containers.
- 9999, 9997 : These are the ports use by the Mule Agent to communicate with the runtime plane.
9. Run the Mule
CMD ["mule"]
mule
as a command, no need to specify the whole path, because we added it to the PATH env variableBuild the Docker Image
Once the Dockerfile is ready we just need to run the following command to build the image:docker build -t mule-runtime:4.8 .
-t
flag assigns a name and an optional tag the Docker image. in this case:mule-runtime
:The name of the image. This is the identifier used to reference the image.4.8:
The tag assigned to this image. Tags help distinguish different versions of an image. This way we could have an image for each mule runtime version.
.
) specifies the build context, which is the directory containing the Dockerfile and other necessary files (e.g., configuration files, application packages). Docker sends this directory to the Docker daemon during the build process.Run the container
Run the container using thedocker run
command:docker run -d --name mule -p 8081:8081 mule-runtime:4.8
-d
- to run the container in the background--name mule
Provides a name for our container-p 8081:8081
Maps the port 8081 in the host to the port 8081 in the container. This is the port we’ll use to expose our app. If we needed more ports/apps we will have to map them here. Also, if we wanted to create a cluster we’d need to open the specific ports for that (see above in the exposed ports of the image)mule-runtime:4.8
The full tag of our image
Verify
Once our container with the Mule runtime is app and running, there are a couple of things we can check to see that’s working.Check the logs
If we check the logs we should find the messages of the start up of the Mule. From your Docker desktop you can access the logs of the container, of from a terminal run:docker logs [YOUR_MULE_CONTAINER]
Deploy an app
Create a hello-world app in Anypoint Studio and export the jar file. Then, copy that jar file into the $MULE_HOME/apps folder of the container. Make sure the port of your test app is 8081 if you’re following this example.Once copied, it will be automatically deployed and you should be able to test it under http://localhost:8081
Push to a Container Registry
If our test was successful, the last step is to make this image available in your container registry, so that you can share it or use from any of your Docker Hosts or Kubernetes environment.For that, we’ll do it in two steps:
- Tag the image
docker tag mule-runtime:4.8 [YOUR_REPO]/mule-runtime:4.8
- Push it to the registry
docker push [YOUR_REPO]/mule-runtime:4.8
where YOUR_REPO
is the public name of your registry or username in docker hub