How to Mount Glusterfs on Docker Host?

Background

A Docker host (such as CoreOS and RedHat Atomic Host) usually is a minimal OS without Gluster client package. If you want to mount a Gluster filesystem, it is quite hard to do it on the host.

Solution

I just worked out a solution to create a Super Privileged Container and run mount in the SPC’s namespace but create the mount in host’s namespace. The idea is to inject my own mount before mount(2) is called, so we can reset the namespace, thank Colin for the mount patch idea. But since I don’t want to patch any existing util, I followed Sage Weil’s suggestion and used ld.preload instead. This idea can thus be applied to gluster, nfs, cephfs, and so on, once we update the switch here The code is at my repo. Docker image is hchen/install-glusterfs-on-fc21

How it works

First pull my Docker image

# docker pull hchen/install-glusterfs-on-fc21

Then run the image in Super Privileged Container mode

#  docker run  --privileged -d  --net=host -e sysimage=/host -v /:/host -v /dev:/dev -v /proc:/proc -v /var:/var -v /run:/run hchen/install-glusterfs-on-fc21

Get the the container’s PID:

# docker inspect --format  {{.State.Pid}}  <your_container_id>

My PID is 865, I use this process’s namespace to run the mount, note the /mnt is in host’s name space

# nsenter --mount=/proc/865/ns/mnt mount -t glusterfs <your_gluster_brick>:<your_gluster_volueme>  /mnt

Alas, you can check on your Docker host to see this gluster fs mount at /mnt.

8 thoughts on “How to Mount Glusterfs on Docker Host?

  1. Great post! Question: you are using the container PID to access the namespace, what happens if that container gets restarted and the PID changes? does it umount the directories or maybe you still have access to the data?

    Like

    1. This was based on an older Docker. It is no longer supported (/proc cannot be bind mount to containers). The mount namespace propagation mode in Docker 1.10 will be the solution to help you mount a filesystem on the host.

      Like

  2. How to improve my credit score? To find out spiaeficclly what you must do to raise your score, you can order your score report from all three national credit bureaus. In addition to your scoreyou still have to pay to find out your credit score, the three-digit number ranging from 300 to 850 that is the key to your borrowing costs.

    Like

Leave a comment