Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mixing Mule and Docker [Snippets]

DZone's Guide to

Mixing Mule and Docker [Snippets]

Learn how to Dockerize a Maven-based Mule project (a simple REST service here), then test the result with Postman.

· Cloud Zone ·
Free Resource

Insight into the right steps to take for migrating workloads to public cloud and successfully reducing cost as a result. Read the Guide.

In this article, a Maven-based Mule project has been Dockerized and tested via Postman.

Our assumption is that you know Docker and Mule.

The project contains a simple REST service deployed on Mule runtime 3.9.

Sample flow image:

Image title

Flow XML:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/dockerhelloworld" doc:name="HTTP Listener Configuration"/>
    <flow name="dockerhelloworldFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <set-payload value="&quot;Hello World. Docker Tested Successfully&quot;" doc:name="Set Payload"/>
    </flow>
</mule>


Dockerfile:

FROM java:8u111-jre

# Install Mule runtime
#RUN cd /opt
RUN wget https://repository-master.mulesoft.org/nexus/service/local/repositories/releases/content/org/mule/distributions/mule-standalone/3.9.0/mule-standalone-3.9.0.tar.gz
RUN tar xvzf mule-standalone-3.9.0.tar.gz
#RUN rm mule-standalone-3.9.0.tar.gz
RUN ln -s /mule-standalone-3.9.0 /mule 


#Start Mule runtime engine
RUN pwd
CMD ["/mule/bin/mule"]

#Deploy Application
Add target/dockerhelloworld-1.0.0-SNAPSHOT.zip /mule/apps/dockerhelloworld-1.0.0-SNAPSHOT.zip


GET service URL: http://localhost:80/dockerhelloworld

Once Dockerizartion is done, you can deploy it on AWS as well.

Running the Project

Go to the folder where the pom.xml is present and run the following commands:

  • mvn clean package

  • docker build -t muledocker .

  • docker run -p 80:8081 --name muledocker muledocker

The service is available on port 80 externally and runs on port 8081 internally.

Docker Logs :: docker run -p 80:8081 --name muledocker muledocker
 ========================================================================== 
MULE_HOME is set to /mule-standalone-3.9.0
Running in console (foreground) mode by default, use Ctrl-C to exit...
MULE_HOME is set to /mule-standalone-3.9.0
Running Mule...
--> Wrapper Started as Console
Launching a JVM...
OpenJDK 64-Bit Server VM warning: ignoring option PermSize=256m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: Using the ParNew young collector with the Serial old collector is deprecated and will likely be removed in a future release
Starting the Mule Container...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

INFO  2017-12-13 06:11:29,424 [WrapperListener_start_runner] org.mule.module.launcher.MuleContainer:
**********************************************************************
* Mule Runtime and Integration Platform                              *
* Version: 3.9.0 Build: 5ed22e1e                                     *
* MuleSoft, Inc.                                                     *
* For more information go to http://www.mulesoft.org                 *
*                                                                    *
* Server started: 12/13/17 6:11 AM                                   *
* JDK: 1.8.0_111 (mixed mode)                                        *
* OS: Linux (4.9.49-moby, amd64)                                     *
* Host: ffb522990698 (172.17.0.2)                                    *
* Mule system properties:                                            *
*  - mule.base = /mule-standalone-3.9.0                              *
*  - mule.home = /mule-standalone-3.9.0                              *
**********************************************************************
INFO  2017-12-13 06:11:29,427 [WrapperListener_start_runner] org.mule.module.launcher.coreextension.DefaultMuleCoreExtensionManager: Initializing core extensions
INFO  2017-12-13 06:11:29,428 [WrapperListener_start_runner] org.mule.module.launcher.coreextension.DefaultMuleCoreExtensionManager: Starting core extensions
INFO  2017-12-13 06:11:29,435 [WrapperListener_start_runner] org.mule.module.launcher.DefaultArchiveDeployer: ================== New Exploded Artifact: default
INFO  2017-12-13 06:11:29,447 [WrapperListener_start_runner] org.mule.module.launcher.MuleSharedDomainClassLoader: Using domain dir /mule-standalone-3.9.0/domains/default for domain default
INFO  2017-12-13 06:11:29,565 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService:
**********************************************************************
* Started domain 'default'                                           *
**********************************************************************
INFO  2017-12-13 06:11:29,571 [WrapperListener_start_runner] org.mule.module.launcher.ArtifactArchiveInstaller: Exploding a Mule artifact archive: file:/mule-standalone-3.9.0/apps/dockerhelloworld-1.0.0-SNAPSHOT.zip
INFO  2017-12-13 06:11:29,583 [WrapperListener_start_runner] org.mule.module.launcher.application.DefaultMuleApplication:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ New app 'dockerhelloworld-1.0.0-SNAPSHOT'                +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2017-12-13 06:11:33,249 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService:
**********************************************************************
* Started app 'dockerhelloworld-1.0.0-SNAPSHOT'                      *
**********************************************************************
INFO  2017-12-13 06:11:33,249 [WrapperListener_start_runner] org.mule.module.launcher.DefaultArchiveDeployer: ================== New Exploded Artifact: default
INFO  2017-12-13 06:11:33,251 [WrapperListener_start_runner] org.mule.module.launcher.application.DefaultMuleApplication:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ New app 'default'                                        +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2017-12-13 06:11:33,995 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService:
***********************************


Postman test result on URL: http://localhost:80/dockerhelloworld

Image title

Source code link: https://github.com/86rishab/MuleHelloWorld_Docker/tree/master

TrueSight Cloud Cost Control provides visibility and control over multi-cloud costs including AWS, Azure, Google Cloud, and others.

Topics:
cloud ,docker ,mule ,postman

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}