DEV Community

taqiyeddinedj
taqiyeddinedj

Posted on • Updated on

DOCKER SWARM CLUSTER & NFS

Docker Swarm emerges as an excellent solution, offering a simple and scalable cluster management system. To complement this, utilizing NFS (Network File System) as a shared volume storage brings significant advantages, providing seamless data sharing and robustness across the Swarm cluster. Moreover, it is essential to emphasize the importance of referring to official documentation for both Docker Swarm and NFS, as it ensures a well-informed and successful setup.

The web app code :

Image description
My Cluster:
Image description
On the NFS Server (NFS Server Host):
The necessary steps and commands to set up an NFS server and mount the NFS share on the client node (Docker Swarm node):
Install NFS Server:
sudo yum install nfs-utils
Create the Shared Directory:
sudo mkdir -p /shared_dir
Export the Shared Directory at /etc/exports:
/shared_dir *(rw,sync,no_root_squash)
Apply the NFS Export Changes:
sudo exportfs –a
Start NFS Server:
sudo systemctl enable nfs-server
On the NFS Client (Docker Swarm Node):
sudo yum install nfs-utils
Create the Target Mount Directory:
sudo mkdir -p /mnt/shared_dir
Mount the NFS Share:
sudo mount -t nfs nfs_server:/shared_dir /mnt/shared_dir

NOTE: fro NFS3 and NFS4 you should explicitly allow Port 2049

Now we create the NFS docker volume on the worker node :
docker volume create --driver local --name website_volume --opt type=nfs4 --opt device=:/shared_dir --opt o=addr=20.111.58.70,rw,nolock
Now Create Docker service with NFS volume :
docker service create --replicas=2 --name hostname_service --restart-condition on-failure -p 80:80 --mount type=volume,source=website_volume,target=/app taqiyeddinedj/hostname_web_app

Top comments (0)