If I have
version: "3.8"
services:
example1:
image: example.com/example1:latest
ports: 8000:80
volumes:
- shared_example:/data
services:
example2:
image: example.com/example2:latest
ports: 8080:80
volumes:
- shared_example:/data
volumes:
shared_example:
driver_opts:
type: nfs
o: "192.100.1.100, nolock,soft,rw"
device: ":/local/shared"
Will that slow things down or is the proper solution to have
volumes:
shared_example1:
driver_opts:
type: nfs
o: "192.100.1.100, nolock,soft,rw"
device: ":/local/shared"
shared_example2:
driver_opts:
type: nfs
o: "192.100.1.100, nolock,soft,rw"
device: ":/local/shared"
Or even
volumes:
shared_example1:
shared_example2:
driver_opts:
type: nfs
o: "192.100.1.100, nolock,soft,rw"
device: ":/local/shared"
You must log in or # to comment.
I don’t know if you had any issue with the formatting, but your first example is not going to work because you are putting the volumes mapping at the top-level. The correct would be:
version: "3.8" services: example1: image: example.com/example1:latest ports: "8000:80" volumes: - shared_example:/data example2: image: example.com/example2:latest ports: "8080:80" volumes: - shared_example:/data volumes: shared_example: driver_opts: type: nfs o: "192.100.1.100, nolock,soft,rw" device: ":/local/shared"
Thank you. That’s what I get for trying to write YAML on my phone.
Pretty sure you only want to define it once?
You create a volume, then map the mount into each service which needs to access it.
I am unsure whether there is performance differences? But the second one looks “wrong”
specific example on sharing data between containers https://www.baeldung.com/ops/docker-share-volume-multiple-containers
Sometimes I get anxious and overthink things. Thank you