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.
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 :
- Install docker plugin for SSHFS with all permission is recommended:
docker plugin install \ --grant-all-permissions vieux/sshfs
- 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
- 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
- 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
- Check the sshvolume what is its configuration and which remote VM it is connected:
docker volume inspect sshvolume3
Docker Volume inspect sshfs
- Now Create an alpine container using the above-created sshvolume3
- Validate now the data created in side the container will be attached volume that is mapped to remote virtualbox
-
Enter the following commands to create a file and store a line of text using echo command.
Docker container using sshfs volume - 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
docker container run --rm -it -v sshvolume3:/data alpine sh
- 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
- List the service and validate it by accessing it.
docker service ls
You can use this remote volume inside docker-compose and also stack deployment YAML files.
Hope you enjoyed this post of learning. please share this with your friends and colleagues.
No comments:
Post a Comment