docker swarm with multiple services on multiple hosts

122 views Asked by At

I am unable to understand if I need application configurations and images loaded in docker on all nodes for docker swarm to work properly?

For example I have app with following dependencies: App -> requires db running App -> also requires volume mount for storing configuration files

So do I need these volumes created with same path on all nodes?

1

There are 1 answers

0
milanbalazs On

You can define your volume in the docker-compose.yml file and the Docker Engine will create it on the node where the service runs. Details:

Example:

version: "3.8"

services:
  db:
    image: db
    volumes:
      - data-volume:/var/lib/db

volumes:
  data-volume:

Note:

The volume is node specific, so the data is stored in the file system on the node/server. It means if your service can run on different nodes then the content of the volume won't be the same on different nodes. In other words, the content of volumes are not synced between the nodes.

Here is a representation of it:

Docker volume node1 Docker volume node2

As you can see in the above pictures the volume is re-created on the "Host C" after re-deployment and the Redis service is not able to access to volume on "Host A".

Here is a good article about persistent storage mechanism for Docker. It describes what happens with your volume if it starts on different node (Re-created):


BUT, there is solution to share the data between machines/nodes. It's not a pure Docker solution but there is a part for it in the official Docker documentation:

Another good description about shared persistent storage with Docker: