Install & Use Docker Volume for Service, Swarm, & Stack in Linux CentOS 7

From Gejoreuy
Jump to navigation Jump to search



When working with services, swarms, and stack, keep in mind that the tasks (containers) backing a service can be deployed on any node in a swarm, and this may be a different node each time the service is updated.
In the absence of having named volumes with specified sources, Docker creates an anonymous volume for each task backing a service. Anonymous volumes do not persist after the associated containers are removed.
If we want our data to persist, use a named volume and a volume driver that is multi-host aware, so that the data is accessible from any node.


Make sure we have installed docker and docker-compose in the server. Please refer how to install it in below links.

Make sure each node in swarm already connected with ssh key to the volume server. So we no need password to be configured in docker volume.

Do the update to the server.

[root@volume ~]# yum update

Install Plugin

Make sure you use root user in installing the plugin. If not, just change the ssh directory path.

[root@volume ~]# docker plugin install vieux/sshfs sshkey.source=/root/.ssh/

Create Docker Volume

[root@volume ~]# docker volume create --driver vieux/sshfs -o sshcmd=root@dh-storage:/root/storage sshvolume

Configure Docker Compose File

Below is the example how docker-compose.yml file configured with docker volume.

version: "3"

    image: image-example
      - "80:8081"
      - "sshfsdata:/mount/it/here:ro"

    driver: vieux/sshfs:latest
      sshcmd: "username@server:/location/on/the/server"
      allow_other: ""