Implementing GlusterFS into Docker

This is a documentation that I made when I implemented GlusterFS into Docker as the container storage solution. It is also a continuation of this previous post as well.

The setup that I used include: 3 Debian 10 VMs with an extra hard disk/drive each and Docker installed with Docker Swarm enabled.

Install the GlusterFS Docker plugin (on all three nodes)

sudo docker plugin install –alias glusterfs trajano/glusterfs-volume-plugin –grant-all-permissions –disable

Set the Gluster servers and enable the plugin (on all three nodes)

sudo docker plugin set glusterfs SERVERS=192.168.5.25,192.168.5.26,192.168.5.27

sudo docker plugin enable glusterfs

Create a subdirectory inside the mounted Gluster volume directory (on the main node)

sudo mkdir -p /mnt/vol1

Create docker-compose.yml to test a simple service

sudo nano docker-compose.yml

version: “3.4”

services:
  foo:
image: alpine
command: ping localhost
networks:
  – net
volumes:
  – vol1:/tmp

networks:
  net:
driver: overlay

volumes:
  vol1:
driver: glusterfs
name: “gfs/vol1”

Deploy the stack

sudo docker stack deploy -c docker-compose.yml test

sudo docker service ls

sudo docker service ps test_foo 

Verification (on the node the container is running on)

sudo docker volume ls

Exec into the container and look at the disk layout:

sudo docker ps

sudo docker exec -it [containerID] sh

Test data persistence

create a file inside the directory that is mapped to the Gluster volume in the container:

echo $HOSTNAME > /tmp/data.txt

cat /tmp/data.txt

Scale the service to 3 replicas:

sudo docker service scale test_foo=3

sudo docker service ps test_foo

Check on another node to see if data.txt persisted

sudo docker ps

sudo docker exec -it [containerID] sh

cat /tmp/data.txt

Append data.txt again and remove the stack 

echo $HOSTNAME >> /tmp/data.txt

cat /tmp/data.txt

sudo docker stack rm test

Deploy the stack again

sudo docker stack deploy -c docker-compose.yml test

sudo docker service ps test_foo

Verify that data.txt persisted on the node that the container is on

docker exec -it [containerID] cat /tmp/data.txt

The data is replicated and stored in the VM itself as well

Leave a comment

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