Getting started with the Docker RBD volume plugin
Docker 1.8 was just released a week ago and with it came the support for volume plugin. Several volume plugins are available but today I will be introducing the Ceph RBD ones (yes there are currently 3 different drivers).
First make sure you at least have the 1.8 version of Docker, if not you can simply run the following:
$ curl -sSL https://get.docker.com/ | sh
As mentioned in the introduction, there are currently 3 different drivers that aim to do the same thing :):
I have to admit that the way I chosed to start with the driver from yp-engineering was really arbitrary. Thus I don’t much knowledge about the others and I can not provide you with much feedback.
Let’s start by installing the necessary components:
$ sudo apt-get install -y golang librados-dev librbd-dev ceph-common xfsprogs
As you see, the RBD volume plugin supports several options cluster name, user The volume plugin has 2 different methods to provision volumes:
- manually, where you have to create the RBD image and put a filesystem on it by yourself. This is interesting when you know that the size of each volume can vary. If it does not you should probably configure the plugin to do it for you.
- automatically, where the plugin will create the image and the filesystem for you.
The service can work with systemd with this unit file. For the purpose of this tutorial, I will run it through stdout.
Before starting the service, I am going to configure Ceph for it:
$ sudo ceph osd pool create docker 128
I like the fact that the volume plugin can configure the volume for me so I will configure it to do so. Let’s start the service:
$ sudo rbd-docker-plugin --create --user=docker --pool=docker &
The driver writes a socket under
/run/docker/plugins/rbd.sock, this socket will be used by Docker to perform the necessary actions (create the volume, do the bindmount etc…).
Now I am going to run a ‘bash’ container to inspect what is happening:
$ sudo docker run -it --volume-driver=rbd --volume foo:/mnt/foo ceph/base bash
What happened under the hood?
The driver did several things:
- created a 20 GB image
- put a XFS filesystem on top of it
- mapped the image and bindmounted the filesystem to the container
After you shutdown the container, the volume will persist (if not using
-rm to run your container) so you can easily run a new container and re-use it.