DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Spinnaker Meets Minikube: Part 1
  • From Monolith to Containers: Real-World Migration Blueprint
  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • Redefining DevOps: The Transformative Power of Containerization

Trending

  • The Twelve-Factor Agents: Building Production-Ready LLM Applications
  • Vision-Language Models in 2026: From Research Breakthroughs to Cloud-Native Production Systems
  • The Window Closes: Why I Switched to Kotlin Before the Codebase Got Too Big
  • Going All In On the JVM 25 Virtual Threads

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Building an ActiveMQ Docker Image on Kubernetes

Building an ActiveMQ Docker Image on Kubernetes

This article will give you a primer on installing Apache ActiveMQ and building it on a Docker image to deploy to Kubernetes.

By 
Nikhil Bhide
·
Oct. 18, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
41.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In our project, we require a message broker to pave a way for asynchronous communication between different microservices. So, one of the microservices required is a messaging service. In this example, we are going to use Apache ActiveMQ as a message broker.

In order to deploy messaging microservice, we must containerize ActiveMQ. It’s a very straightforward process as we are only going to set up 1 node cluster.

Technically we require taking the base image of Linux and getting and installing ActiveMQ 5.16.5. The final step is to start ActiveMQ. So, let’s get started.

  • Create a Docker file, a script file with following instructions.

FROM openjdk:8-jre-alpine
RUN wget -O activemq.tar.gz http://archive.apache.org/dist/activemq/5.15.6/apache-activemq-5.15.6-bin.tar.gz 
RUN tar -xzf activemq.tar.gz 
CMD ["apache-activemq-5.15.6/bin/activemq", "console"]


  • Navigate to the folder in which the Docker file is saved and create a Docker image by running command  docker build :

Image title

  • Check whether the image is registered in local Docker repo with Docker images.

Note that initially you will notice <none> under repository. In order to tag the image, run command docker tag <IMAGE_ID> <yourdockerhubname>/image-name.

For example: docker tag c35d0594bffc nikbhi15docker/k8s-make-my-vacation-queue .Image title


  • Run the container using Docker using command:

  •  docker run nikbhi15docker/k8s-make-my-vacation-queue 


    Image title


    • Find out IP address of our container and connect to admin console on <container_ip>:8161.Image title


    Image title

    Image title



    Image title


    Okay, so ActiveMQ started. But seriously, what the heck is happening? Let's understand!

    Those who are familiar with Docker can simply stop reading this article and go for a coffee break. Others hold on!

    The entire magic is in the Docker file – YES only 4 instructions.

    FROM openjdk:8-jre-alpine


    It implies that we want to use the base image of openJDK:8-jre-alpine. Its one of the smallest Linux Java images with Alpine. If you are observing carefully, then you will have noticed the usage of openjdk and not Oracle JDK. Yes, it’s now official that OpenJDK has better official images than Oracle JDK. Even the regular images are smaller, including the alpine alternatives.

    RUN wget -O activemq.tar.gz http://archive.apache.org/dist/activemq/5.15.6/apache-activemq-5.15.6-bin.tar.gz


    It’a no-brainer. This instruction is downloading the MQ setup artifact from thr official Apache ActiveMQ site and this command is getting executed on the top of our Linux base image. So after this, you have Linux, Java and ActiveMQ.

    I am sure by now you must have understood the gist of this article and you can definitely anticipate what is to be followed in this article. However, I will still explain the remaining steps from the perspective of completeness of this article.

    RUN tar -xzf activemq.tar.gz


     tar is Short for Tape Archive, and sometimes referred to as tarball, a file that has the TAR file extension is a file. Above command unpacks the tar.gz file.

     -xzf are nothing but different flags/arguments passed to tar  command.

     -x --extract  = extract files from an archive

     -z, --gzip = gzipped files eg. for tar.gz packages

     -f, --file ARCHIVE  = use archive file or device ARCHIVE

    CMD ["apache-activemq-5.15.6/bin/activemq", "console"]


    Here we are using default entry point which is  /bin/sh –c . The CMD specifies arguments that will be fed to the ENTRYPOINT. The format of command CMD is

     CMD ["executable","param1","param2"] 

    Therefore what we are doing is forking out a process

     /bin/sh -c command param1 param2 . This is how the ActiveMQ process gets started.

    That’s it in this article. In the next article, we will see how to use a Spring Boot JMS application to connect with this messaging service in microservices architecture using K8s.

    Just wait a moment!

    We have not yet accomplished the mission. Our mission is to run this image on K8s. Let’s cross the finish line in the last section of this article.

    In order to run this Docker image on K8S, we require the pod and service definition. Here are those definitions.

    Pod definition – Notice carefully that in this example, I am using image pushed to my Dockerhub that is nikbhi15docker/k8s-make-my-vacation-queue.

    Image title


    Service definition – Notice that we are using nodePort and thrport to be exposed is 32090 and from the container the port is 8161. NodePort exposes the service on each Node’s IP at a static port.

    Image title

    Start minikube using command  minikube start .

    Then navigate to the directory in which queue-pod and queue-service definitions are saved. Apply pod and service definitions as follows. In short, applying definition implies that you are starting a pod and a service.


    kubectl apply –f queue-pod.yaml



    kubectl queue-service.yaml


    Find the IP address of minikube cluster (minikube ip) and navigate to :32190   and you should admin console of ActiveMQ (username – admin & password – admin).

    You can refer to GitHub.

    Docker (software) Kubernetes Archive file microservice Command (computing)

    Opinions expressed by DZone contributors are their own.

    Related

    • Spinnaker Meets Minikube: Part 1
    • From Monolith to Containers: Real-World Migration Blueprint
    • Fast Deployments of Microservices Using Ansible and Kubernetes
    • Redefining DevOps: The Transformative Power of Containerization

    Partner Resources

    ×

    Comments

    Loading comments

    The comments didn't load

    Please try again in a moment.

    Likes

    Loading

    The next likes didn't load. Please try again.

    The likes didn't load

    Please try again in a moment.

    See who liked this

    Log in or join DZone for free to see who liked this article.

    Log in Join for free
    • RSS
    • X
    • Facebook

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 215
    • Nashville, TN 37211
    • [email protected]

    Let's be friends:

    • RSS
    • X
    • Facebook