Running MonetDB in containers

Containers are a modern way to run applications. We publish an image of MonetDB at docker hub every time there is a new MonetDB release, and you can use those images as part of your applications.

Basic use

You can use the latest version like this:

docker run -p 50001:50000 monetdb/monetdb:latest

The above command downloads the latest image from docker hub and starts a container with it. It maps port 50000 of the container to port 50001 of the host. By default, the container starts the MonetDB daemon that serves a database named demo.

You can use mclient on the host machine to connect to the database (with the default username and password ‘monetdb'):

mclient -d demo -p 50001

You can override the program that the container starts (also called the entrypoint of the image), by specifying the program to run when starting the container:

docker run -it -p 50001:50000 monetdb/monetdb:latest /bin/bash

This command will start the bash inside the container. Any program installed, and specifically, all of the MonetDB suites is available. You can use the daemon client to create new databases and mclient to connect to one of the databases. In addition, the databases are accessible outside of the container.

Data persistence

To be able to keep the data in the database even after, you should use either bind mounts or docker volumes.

Docker itself recommends using volumes:

docker volume create data-vol
docker run -it -v data-vol:/var/monetdb5/dbfarm -p 50001:50000 monetdb/monetdb:latest

For bind mounts, you should initialize a dbfarm before mounting the directory:

mkdir /path/to/dbfarm
monetdbd create /path/to/dbfarm
docker run -it -v /path/to/dbfarm:/var/monetdb5/dbfarm -p 50001:50000 monetdb/monetdb:latest

Managing databases

To manage multiple databases, you need to create them using the tools inside the container.

Begin by running a shell inside the container:

docker run -it -v data-vol:/var/monetdb5/dbfarm -p 50001:50000 monetdb/monetdb:latest /bin/bash

And then in the container:

[root@c2c6432ab0e2 monetdb]# monetdbd start /var/monetdb5/dbfarm
[root@c2c6432ab0e2 monetdb]# monetdb create -p monetdb new-db
[root@c2c6432ab0e2 monetdb]# exit

Then, after restarting a new container, attaching the volume you specified earlier, you should be able to connect to the database:

docker run -it -v data-vol:/var/monetdb5/dbfarm -p 50001:50000 monetdb/monetdb:latest
mclient -d new-db -p 50001

Epilogue

This blog was a small primer on using the MonetDB images we publish at docker hub. Containers is an easy-to-use technology but have some caveats and pitfalls that users should know if they are to use it successfully. We hope that the above exposition will help you with it.