One of new interesting feature added in Apache Karaf 4.2.1 is the support of Docker.

Docker is a great system container platform. Mixing Docker (system container) and Apache Karaf (application container) together gives a great flexibility and very powerful approach for your applications and ecosystem. You decide of the provisioning approach you want to adopt:

When you use docker run you have to remember to expose the network ports using the -p option. When you expose 8101 you can connect to the Karaf running inside the Docker container using ssh or Karaf bin/client.

An alternative to docker run (or docker start) is to use docker-compose. Apache Karaf now provides docker-compose.yml to simplify the way to starting and stopping Apache Karaf in docker.

Docker image with custom Karaf distribution

You have created your own Karaf custom distribution based and you want to create a Docker image with it ? Very simple with build.sh script ! You just have to provide the archive of your custom distribution.

Basically, the Karaf docker feature is a way of interacting with the Docker service as you can do directly with the docker commands.

However, it also provides an unique feature: the provisioning.

Karaf Docker provisioning

You have a running Karaf instance where you install bunch of features, bundles, change configuration, …

You want to create a Docker container using this instance ? Simpy use the docker:provision command. It will create a Docker container with your instance as a container volume, starting it automatically.