Running Karaf+Hawtio+Camel inside Docker

These days microservices is hot and running things in a container is helping that. Docker has received a lot of attention for this, and rightly so, when things work 😉 I will just mention very briefly what docker is but I recommend the official tutorial. It is a good walk through.

Docker is basically a tool that gives you the ability to run a single process/application isolated inside a linux machine. In a sense, you write a dockerfile a bunch of instructions about which application you want, how to install it, how to run it and to keep it running. Then you build that image and run it. Once it is running it is as if the application is running on your host except as docker container. The beauty of it is that it is scalable and can run on any host that can run docker. But yeah read more on dockerhub.

Now if you want a docker image with Apache Karaf 4.0.2, Hawtio 1.4.58 and Camel 2.15.1 I have setup an image on my repository. See the link below.

https://hub.docker.com/r/soucianceeqdamrashti/karaf/

Everything is in default state. If you need to change the pax logging log4j config you need to override the file. If you want the deploy folder to exist externally you need to add a volume.

You run it by issuing this command:

docker run -d -p 8181:8181 –name karaf karaf:4.0.2

The dockerfile instructions look as follows:

#Run using docker command
# docker run -d -p 8181:8181 –name karaf karaf:4.0.2
FROM java:8u66
MAINTAINER soucianceeqdamrashti <souciance.eqdam.rashti@gmail.com>
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV KARAF_VERSION=4.0.2
RUN mkdir /opt/karaf
ADD http://apache.openmirror.de/karaf/${KARAF_VERSION}/apache-karaf-${KARAF_VERSION}.tar.gz /opt/karaf/
WORKDIR /opt/karaf/
RUN tar –strip-components=1 -C /opt/karaf -xzf apache-karaf-${KARAF_VERSION}.tar.gz;
WORKDIR /opt/karaf/
RUN bin/start && \
#allow the Karaf process to start
sleep 10 && \
#install camel repo url and version
bin/client feature:repo-add camel 2.15.1 && \
#allow feature url installation to complete
sleep 5 && \
#install camel core
bin/client feature:install camel
RUN sleep 10
RUN bin/start && \
#allow the Karaf process to start
sleep 10 && \
#install camel repo url and version
bin/client feature:repo-add camel 2.15.1 && \
#allow feature url installation to complete
sleep 5 && \
#install camel core
bin/client feature:install camel
RUN sleep 10
RUN bin/start && \
#allow the Karaf process to start
sleep 10 && \
#install hawtio repo url and version
bin/client feature:repo-add hawtio 1.4.58 && \
#allow feature url installation to complete
sleep 5 && \
#install hawtio
bin/client feature:install hawtio
#COPY /config/org.ops4j.pax.logging.cfg /opt/karaf/etc/
EXPOSE 8181
ENTRYPOINT [”/opt/karaf/bin/karaf”, ”start”]

Most of the commands are pretty self-explanatory. You may wonder why there is a sleep command. This is because I noticed that you cannot simply start Karaf and then go ahead and install the feature. Docker immediately goes to the install part after the start command not giving Karaf enough time to kick in. That is why there is a sleep to allow it to kick in and then go ahead and install the camel and hawtio parts.

At the ENTRYPOINT I am starting Karaf as a foreground process. This is because docker requires this, otherwise if you start Karaf as a background process docker things the application has finished and exists. Your container will simply exist.

Annonser

Kommentera

Fyll i dina uppgifter nedan eller klicka på en ikon för att logga in:

WordPress.com Logo

Du kommenterar med ditt WordPress.com-konto. Logga ut / Ändra )

Twitter-bild

Du kommenterar med ditt Twitter-konto. Logga ut / Ändra )

Facebook-foto

Du kommenterar med ditt Facebook-konto. Logga ut / Ändra )

Google+ photo

Du kommenterar med ditt Google+-konto. Logga ut / Ändra )

Ansluter till %s