Docker SSHFS plugin external storage as Docker Volume

 Namaste, In this exciting Docker storage volume story, this experiment is going to use two Vagrant VirtualBox. You can also use any two Cloud instances (may be GCP, AWS, Azure etc.,). Where DockerHost is going to run the docker containers and DockerClient box is going to run the SSH daemon. 

SSHFS Volume in docker


Docker Volume with External Storage using SSHFS

Docker allows us to use external storage with constraints. These constraints will be imposed on cloud platforms as well. The external or Remote volume sharing is possible using NFS. 

How to install SSHFS volume?


Step-by-step procedure for using external storage as given below :
  1. Install docker plugin for SSHFS with all permission is recommended:
    docker plugin install \
    --grant-all-permissions vieux/sshfs
    
  2. Create a Docker Volume
      docker volume create -d vieux/sshfs \
    -o sshcmd=vagrant@192.168.33.251:/tmp \
    -o password=vagrant -o allow_other sshvolume3
    
  3. Mount the shared folder on the remote host:
    mkdir /opt/remote-volume # In real-time project you must have a shared volume accross ECS instances
    
  4. The remote box in my example, it is a 192.168.33.251 box. check the PasswordAuthentication value, the default value will be no, but if your volume using this remote box communication happen when you provide the ssh login password vagrant@dockerclient1:/tmp$ sudo cat /etc/ssh/sshd_config |grep Pass PasswordAuthentication yes
  5. Check the sshvolume what is its configuration and which remote VM it is connected:
         docker volume inspect sshvolume3
      

    docker inspect sshfs volume
    Docker Volume inspect sshfs 

  6. Now Create an alpine container using the above-created sshvolume3
  7.   docker container run --rm -it -v sshvolume3:/data alpine sh
      
  8. Validate now the data created in side the container will be attached volume that is mapped to remote virtualbox
  9. Enter the following commands to create a file and store a line of text using echo command.
    sshfs using container
    Docker container using sshfs volume
  10. On the remote box check that the file which is created inside the container will be available on the remote box 192.168.33.251 box
Remote box /tmp containers file


    You can use this remote volume inside docker-compose and also stack deployment YAML files.
  1. Create a service that uses external storage
    docker service create -d \
     --name nfs-service \
     --mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/,"volume-opt=o=10.0.0.10,rw,nfsvers=4,async"' \
     nginx:latest
    
  2. List the service and validate it by accessing it.
    docker service ls
        

Hope you enjoyed this post of learning. please share this with your friends and colleagues.

Comments

Popular posts from this blog

Ansible Jinja2 Templates: A Complete Guide with Examples

Ansible 11 The uri module with examples

Jenkins Active choices parameter - Dynamic input