DEV Community

taqiyeddinedj
taqiyeddinedj

Posted on • Edited on

1

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay