Docker Swarm creates a stack with named services, and the services create containers that are disposable with unique names. It is bad practice to reference container names in a stack. The service name is in the docker-stack.yaml
file. If you are looking to create a docker stack with persistent volumes, it is better to create a persistent volume
instead. docker volume create [OPTIONS] [NAME]
Docker volume create
You can also create it when you start your stack in your docker-stack.yaml
. All containers spawn from my-service will use the same shared volume.
version: "3.8"
services:
my-service:
image: my-service:latest
volumes:
- my-data:/usr/share/mydata
volumes:
my-data
You may also reference an externally-created volume (with docker volume create my-data
) with this instead:
volumes:
my-data:
external: true