Followers

Docker Volume with NFS

  Creating a Docker volume that uses NFS and mounting it in a Docker container involves multiple steps. Here's a complete example of how...

 Creating a Docker volume that uses NFS and mounting it in a Docker container involves multiple steps. Here's a complete example of how to create an NFS volume, mount it in a Docker container, and test it:

Assumptions:

  • You have a server with NFS configured and a shared directory.
  • You have Docker installed on both the server and the client.
  1. Set Up NFS Server:

    On the server, ensure that NFS is installed and configured to export a directory. Edit /etc/exports to include a line like:

    /path/to/shared/folder *(rw,sync,no_subtree_check,no_root_squash)
    

    Replace /path/to/shared/folder with the actual path to the shared directory. After editing the file, restart the NFS server:

    sudo systemctl restart nfs-kernel-server
  2. Mount NFS Share on Client:

    On the client machine, mount the NFS share:

    sudo mount -t nfs -o nfsvers=4 SERVER_IP:/path/to/shared/folder /mnt/nfs

    Replace SERVER_IP with the IP address or hostname of the NFS server.

  3. Create a Docker Volume Using NFS:

    On the client machine where Docker is installed, create a Docker volume that uses NFS:

    docker volume create --driver local \
    --opt type=nfs \
    --opt o=addr=SERVER_IP,rw \
    --opt device=:/path/to/shared/folder \
    my-nfs-volume
    • --opt type=nfs: Specifies the volume type as NFS.
    • --opt o=addr=SERVER_IP,rw: Specifies the NFS server address and read-write permissions.
    • --opt device=:/path/to/shared/folder: Specifies the NFS mount path.
  4. Run a Docker Container with the NFS Volume:

    Now, you can run a Docker container that uses the NFS volume:

    docker run -d --name my-container -v my-nfs-volume:/data nginx

    In this example, an NGINX container is started with the /data directory mounted to the my-nfs-volume.

  5. Test the NFS Volume:

    Inside the container, you can create, read, and write files in the mounted NFS volume. For example:

    # Attach to the running container
    docker exec -it my-container sh
    
    # Create a test file in the NFS volume
    echo "Hello, NFS!" > /data/test.txt
    
    # Check if the file exists
    cat /data/test.txt

    You should see the "Hello, NFS!" message, confirming that the container can read and write to the NFS volume.

That's it! You have successfully created an NFS volume, mounted it in a Docker container, and verified that the container can access the shared NFS data. This setup allows you to share data between containers running on different hosts using NFS as the storage backend.

COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Docker Volume with NFS
Docker Volume with NFS
DevOpsWorld
https://www.devopsworld.co.in/2023/10/docker-volume-with-nfs.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2023/10/docker-volume-with-nfs.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content