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!

5 thoughts on “Countly in a Docker container”

  1. I woukd prefer using ‘docker create’ when adding a volumne container. It’ll be created (voluem is up) but status won’t be exited, which is a flag for some housekeeping services that this container can be deleted. Also, indicates that this container is not intended “to run”.

    1. Nice, I was not aware of “docker create” which was added in docker version 1.3 as it seems.

      Thanks for the hint, I will update the post.

Leave a Reply