Building GlusterFS in a docker container

Although Setting up a glusterfs environment is a pretty simple and straightforward procedure, Gluster community do maintain docker images for gluster both in Fedora and CentOS in the docker hub for the ease of users. This blog is intended to walk the user through the steps of running GlusterFS with the help of docker.
The community maintains docker images GlusterFS release 3.6 in both Fedora-21 and CentOS-7. The following are the steps to build the GlusterFS docker images that we maintain:
To pull the docker image from the docker hub run the following command:
For GlusterFS-3.6 in Fedora-21

For GlusterFS-3.6 in CentOS-7

This will fetch and build the docker image for you from the docker hub.
Alternatively, one could build the image from the Dockerfile directly. For this, one should pull the Gluster-Fedora Dockerfile from the source repository and build the image using that. For getting the source, One can make use of git:

This repository consists of Dockerfiles for GlusterFS built in both CentOS and Fedora distributions. Once you clone the repository, to build the image, run the following commands:
For Fedora,

For CentOS,

This command will build the docker image from the Dockerfile you just cloned and will be assigned the name gluster-fedora or gluster-centos respectively. ‘-t’ option is used to give a name to the image we are about the build.
Once the image is built in either of the above two steps, we can now run the container with gluster daemon running. For this run the command:
Step 1:

( is either gluster-fedora or gluster-centos as per the configurations so far)
This is running container in detach mode, init script runs behind the screen.
Once docker returned the container id, you can get into the container via below command.

In This mode it runs the init scripts in the container, you have to detach from this process.
To detach this container you can press Ctrl p + Ctrl q

Systemd has been installed and is running in the container we maintain. This is to ensure that gluster daemon is up and running by the time we boot up our container and also to deal with the “Failed to get D-Bus connection” issue. To fix the issue Dan Walsh’s blog on the same matter has been the only resource: developerblog.redhat.com/2014/05/05/running-systemd-within-docker-container/
For systemd to run without crashing it is necessary to run the container in the privileged mode since systemd requires CAP_SYS_ADMIN capability. As per the help of docker run shows, ‘-t’ option is given to allocate a pseudo-TTY and ‘-i’ stands for the interactive mode which keeps STDIN open even if not attached. The port 22 has been published to the host so that one can ssh into the container that will be running once this command is issued. In the docker file, the password for the root has been changed to ‘password’ for user to ssh into the running container.
One issued, this will boot up the Fedora or CentOS system and you have a container started with glusterd running in it. Now to login to the container, one need to inspect the IP of the container running. To get the ID of the container, one can do:

Note the Container ID of the image and inspect the image to get the IP address. Say the Container ID of the image is d273cc739c9d , so to get the IP do:

Note:
If you want to keep the glusterfs configurations persistent then you have to create directories (/etc/glusterfs, /var/lib/glusterd, /var/log/glusterfs and appropriate bricks for the volume /brick1) and bind mount it to the container.
For example:

:z is to set the selinux label with the bind mount on the go.

That’s it!

1 thought on “Building GlusterFS in a docker container”

  1. Hi…it’s not clear where we format, create and mount the Gluster bricks in this case… can you advise?

    In my case, I’m trying to add a 1 TB dedicated drive to hold Gluster-replicated data. I’ve got the container running as expected, but not sure how to get the drive integrated with it.

Leave a Reply

Your email address will not be published. Required fields are marked *