Apache Karaf on Azure Cloud

Apache Karaf on Azure Cloud

In the previous articles, we have been able to understand the "new" Docker. In this one, we will use a Karaf Docker image on the Azure Cloud.

Adaptation of the article: "Apache Karaf on Azure Cloud " of blog Nanthrax  written by Jean-baptiste Onofré (Technical Advisor)

Creation of the Karaf Docker image

From a running Karaf instance, we install the Karaf example REST. Thus, we are changing etc/org.apache.karaf.features.cfg to add the example REST like featuresBoot :

featuresRepositories = \ 
    mvn:org.apache.karaf.features/enterprise/4.2.1/xml/features, \
    mvn:org.apache.karaf.features/spring/4.2.1/xml/features, \
    mvn:org.apache.karaf.features/standard/4.2.1/xml/features, \
    mvn:org.apache.karaf.features/framework/4.2.1/xml/features, \
featuresBoot = \ 
    instance/4.2.1, \
    package/4.2.1, \
    log/4.2.1, \
    ssh/4.2.1, \
    framework/4.2.1, \
    system/4.2.1, \
    eventadmin/4.2.1, \
    feature/4.2.1, \
    shell/4.2.1, \
    management/4.2.1, \
    service/4.2.1, \
    jaas/4.2.1, \
    deployer/4.2.1, \
    diagnostic/4.2.1, \
    wrap/2.5.4, \
    bundle/4.2.1, \
    config/4.2.1, \
    kar/4.2.1, \

We package the Karaf folder in an archive tar.gzmore precisely by kloud.tar.gz :

tar zcvf kloud.tar.gz apache-karaf-4.2.1

Now, as explained in the image article, we create the image of Karaf Docker using assemblies/docker/build.sh provided in the Karaf distribution: GitHub link

./build.sh --from-local-dist --archive ~/path/to/kloud.tar.gz --image-name kloud
Using karaf dist: /home/jbonofre/Workspace/kloud/kloud.tar.gz
Sending build context to Docker daemon  79.36MB
Step 1/10 : FROM java:8-jre-alpine
 ---> fdc893b19a14
 ---> Running in c48b1e2bf909
Removing intermediate container c48b1e2bf909
 ---> f6cc4d99d965
Step 3/10 : ENV KARAF_HOME $KARAF_INSTALL_PATH/apache-karaf
 ---> Running in ae61251f9332
Removing intermediate container ae61251f9332
 ---> 8092cc15e2d3
Step 4/10 : ENV PATH $PATH:$KARAF_HOME/bin
 ---> Running in 9ae9f2ebe44c
Removing intermediate container 9ae9f2ebe44c
 ---> b107423b2920
Step 5/10 : ARG karaf_dist=NOT_SET
 ---> Running in 15340610bc2d
Removing intermediate container 15340610bc2d
 ---> 075b9981d66b
Step 6/10 : ADD $karaf_dist $KARAF_INSTALL_PATH
 ---> dee79a14fe7d
Step 7/10 : RUN set -x &&   ln -s $KARAF_INSTALL_PATH/apache-karaf* $KARAF_HOME
 ---> Running in 6f1f292aa5f6
+ ln -s /opt/apache-karaf-4.2.1 /opt/apache-karaf
Removing intermediate container 6f1f292aa5f6
 ---> d2aea8c4ef8e
Step 8/10 : COPY docker-entrypoint.sh /
 ---> 454600e6f558
Step 9/10 : EXPOSE 8101 1099 44444 8181
 ---> Running in 581aba587bdc
Removing intermediate container 581aba587bdc
 ---> b4595b7e944d
Step 10/10 : ENTRYPOINT ["/docker-entrypoint.sh"]
 ---> Running in 1f49d86b563c
Removing intermediate container 1f49d86b563c
 ---> de6ac03845bd
Successfully built de6ac03845bd
Successfully tagged kloud:latest

We now have our kloud Karaf Docker image:

gt; docker images REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE kloud                                      latest              de6ac03845bd        58 seconds ago      198MB ...

You can test your image:

gt; docker run -i --name kloud -p 8181:8181 kloud Starting Apache Karaf

We can now consult the WADL of our service REST available on http://localhost:8181/cxf/booking?_wadl. So, the Docker image is ready, that's the one we're going to push and run on the Azure Cloud.

Creation of the Azure container register

As the image is not available on DockerHub "public", we will create our container registry on Azure: similar to the local DockerHub on a cloud platform. We first create the container register in the Azure resources:


We now have our container register available:


We can push our image of kloud Karaf Docker on this container register.

Push an image of Karaf Docker on the Azure container register

We now have our container register available:


Now, we connect to the Azure docker from our deamon local docker :

gt; docker login -u karaf -p xxxxx karaf.azurecr.io WARNING! Using --password via the CLI is insecure. Use --password-stdin. Login Succeeded

We can now create a tag and press the container karaf.azurecr.io Azure Docker :

gt; docker tag kloud karaf.azurecr.io/kloud

gt; docker push karaf.azurecr.io/kloud The push refers to repository [karaf.azurecr.io/kloud] 8fc85780c222: Pushed df9688476ce7: Pushed 5e5beed17b78: Pushed 20dd87a4c2ab: Pushed 78075328e0da: Pushed 9f8566ee5135: Pushed latest: digest: sha256:be6ce4c0cf223cf16ebc6f22ce9458828a229214e71d9ba1dd9a1c16daf22bd7 size: 1573

We can see our image on our Azure container register:


Creation and execution of a container on Azure

Now that our kloud image is on the Azure container register, we can create a Docker container on Azure. This is the Azure Container instance:


We call our container kloud :


We configure to expose port number 8181 (the default HTTP port number used by Karaf):


We are ready to create our container (note that we use the start mode run karaf because tty is not bound by default on cloud):


We can see our container start logbook:


We can possibly connect to our container:


In the container overview, we can see the load and IP given to your container:


This means that our example service REST is available on public IP: example container


It is also possible to use the DNS that we have defined on the container instance, this means that our service REST is available on in this link :


Next step: Azure Kubernetes Service

Now that we have all the resources available to use the Azure Cuba network service: we can have several cloud containers running as Kubernetes POD and create a Kubernetes service for example REST.

Blocked in your roadmaps?

Would you like to train your teams?

en_GBEnglish (UK)
fr_FRFrançais en_GBEnglish (UK)