Update to my previous post on Countly

Shortly after I published my post on Countly in a Docker container my pull request was approved, adding the Dockerfile directly to the Countly github repository.

So now it is possible to build the Countly Docker image simply by running:

Countly even created an official Docker hub repository under https://registry.hub.docker.com/u/countly/countly-server/ which means you do not have to build the image yourself, just run it via

The image will be pulled from the repository and launched on your host – the simplest way to try out Countly.

Countly in a Docker container

We are using Countly to track and analyse usage of our various mobile apps at troii. Since we are hosting Countly ourself, and I am in the process of moving all our hosted services and apps into Docker containers, Countly was next.

Dockerfile

Of course the first thing to do when starting with creating a Docker container for a specific application is to look for already existing ones. I found two, but but none of them worked out of the box. The one from dz0ny looked best so I forked the repository and based my efforts on it.

The resulting Dockerfile for Countly looks like:

Most of the changes I made were combining multiple RUN statements into a single line to minimize the number of intermediate images created. See Best practices for writing Dockerfiles why this is should be done.

The Docker images uses supervisor to run nginx, mongodb and counlty inside one container. This contradicts the rule “Run only one process per container” from Best practices for writing Dockerfiles but because I do not have any mongodb Docker image running currently I did not change that.

Data volumes

As one comment on my last post on Docker pointed out, I glossed over the part on how to create a data volume, so this time I will explain it in detail.

To create a data volume for my Countly Docker container I run the following command:

After running this command line, there is a stopped container named countly_data with a volume /data. We can use this container to persist the data created by the mongodb Countly is using. We do this by running the Countly Docker container with the following command line:

This starts the Countly Docker container named “countly” using the volume from the data container countly_data. The parameter --restart="always" automatically restarts the container if the docker daemon is restarted.

You can find the full Countly Docker repository at https://github.com/troii/docker-countly. I would be very happy about your feedback!