I have a docker container, which has its volume mounted with host volume. Here is its docker-compose service:
core:
image: index.docker.io/kaushal/demo_img
volumes:
- ./data/custom:/opt/custom:z
Here ./data/custom
is host directory and it's mounted with /opt/custom
dir in container. Now, to achieve high availability, I want to run multiple replicas of this container using docker swarm on different nodes.
When I start swarm, it always shows 0/2
replicas. The reason is highlighted here: https://stackoverflow.com/a/56707801/5353128 (tl;dr because I don't have ./data/custom
dir in other swarm node).
This problem seems to be the common problem with docker swarm but I couldn't find the straightforward solution for this. Some of the SO posts suggests to use shared volumes but it's not clear how to implement such shared volume for such a simple usecase.
Also, is there any alternative to shared volumes? Any reference would be appreciated. Thanks!