Search code examples
dockerdocker-swarmglusterfs

docker share volumes with glusterfs


I want to test docker in Swarm mode.

I've created 3 Ubuntu-server Virtual Machines.
On each VM I've installed docker.

The next step that I would like to accomplish is to share the /var/lib/docker/volumes folder among the 3 docker nodes.
The first solution I tried is to mount /var/lib/docker/volumes as a remote sshfs volume. I failed because when the docker service starts it executes the command chown on the /var/lib/docker/volumes and it fails.

Then I tried to use glusterfs, I succeded to configure gluster to share the same folder on the 3 nodes (now if I create a file in /var/lib/docker/volumes on the first node, I can see the new file also on the others 2 nodes).

Then I started docker on the first node without any problem. But If I try to start docker on the second node I got the error:

Error starting daemon: error while opening volume store metadata database: timeout

I assume that the error is because the first node acquire the lock on the file /var/lib/doceker/meradata.db

How can I solve this problem? Is there an alternative to use glusterfs to share the docker volumes folder?

Thank you


Solution

  • You shouldn't share this directory at all. It will probably lead to data corruption. As you already have glusterfs configured you can mount gluster dir into container with -v /path/to/gluster/mount:/path/in/container flag added to docker run. Then files written to path in container will be shared among gluster nodes. Other option is to use some dedicated volumes driver for that. Try searching for 'docker volumes drivers' in your favorite search engine.