Hello docker

Fathima Dilhasha
The DevOps Journey
Published in
3 min readApr 7, 2017

Docker is a software container platform. Developers use Docker to eliminate machine specific issues.

You can install docker using following commands.

You can refer https://docs.docker.com/engine/installation/ to get docker installed in your machine.

I am using ubuntu OS and I will discuss on how you can get separate images for WSO2 ESB and Activemq.

A Dockerfile provides instructions for Docker to build a docker image.
For each line in the Dockerfile, a new docker image is built, if that line results in a change to the image used.

You can create you own images and commit them to Docker Hub so that you can share them with others. The Docker Hub is a public registry maintained by Docker, Inc. that contains images you can download and use to build containers.

How to create a docker image for WSO2 ESB.

Prerequisites:

  1. Download zip file of wso2esb-5.0.0
  2. Create a file named “Dockerfile” in the same path

Dockerfile:

Following is the content in the Docker file to create an ESB image.

FROM ubuntu:14.04

MAINTAINER dilhasha dilhasha@wso2.com

# Install Java.
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1–1 select true | debconf-set-selections && \
apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java8-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer

RUN \
apt-get update && \
apt-get install zip -y

COPY wso2esb-5.0.0.zip /opt

WORKDIR “/opt”

RUN unzip /opt/wso2esb-5.0.0.zip

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

RUN chmod +x /opt/wso2esb-5.0.0/bin/wso2server.sh

EXPOSE 9444

CMD [“/opt/wso2esb-5.0.0/bin/wso2server.sh”]

In the above dockerfile, we install java and then copy the ESB file and start the ESB. Let’s see what each of the keywords in the Dockerfile mean.

FROM : The base image from which we start building our custom image

RUN : Runs commands that are specified — as a root user using sh -c “your-given-command”

COPY : will copy a file from the host machine into the container

WORKDIR : sets location from which to run commands from

EXPOSE: Will expose a port to host machine(Allows us to access esb’s management console)

CMD : Will run a command. This is usually the long-running process in the container. Here, we are running the wso2server.sh script.

Now we can build this Dockerfile using the below command. <name> can be anything you prefer. This will look for a file named “Dockerfile” and run it.

docker build -t <name> .

After the above command exists, you will see a success message as below.

Successfully built <image_id>

Now, you can start the container using the below command.

sudo docker run -p <port_to_expose>:<port_in_host_machine> -t <image_id>

For the ESB example, port to export is “9443” and you can use any port you prefer in your host machine to expose it.

When you run above command you’ll notice that ESB gets started and you can access the management console at “http://localhost:<port_in_host_machine>”.

How to create a docker image for Apache activemq.

Prerequisites:

  1. Download zip file of apache-activemq-5.14.4
  2. Create a file named “Dockerfile” in the same path

Following is the Dockerfile used to build an Activemq image.

FROM ubuntu:14.04

MAINTAINER dilhasha dilhasha@wso2.com

# Install Java.
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1–1 select true | debconf-set-selections && \
apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java8-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer

RUN \
apt-get update && \
apt-get install zip -y

COPY apache-activemq-5.14.4.zip /opt

WORKDIR “/opt”

RUN unzip /opt/apache-activemq-5.14.4.zip

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

RUN chmod +x /opt/apache-activemq-5.14.4/bin/activemq

EXPOSE 8161

CMD [“/opt/apache-activemq-5.14.4/bin/activemq”,”console”]

The only new thing in this Dockerfile is the below line.

CMD [“/opt/apache-activemq-5.14.4/bin/activemq”,”console”]

This CMD [“command” , “parameter”] format helps us to provide an additional parameter to our script.

You can use the same commands as in the previous section and see that the activemq instance gets started in console mode.

Thanks :)

--

--