0

How do multiple containers(create from same image) access the directory(packaged in the image) in other container? There are some ways not elegant:

  1. Mount directory into a shared volume or host path. When a container changed files in the directory, other containers will perceive it. Is there any idea to make shared volume working like copy-on-write?
  2. Create a volume for each container, and copy directory into the volume. In this way, the directory have to save multiple copies in disk.

I've browsed this problem [https://stackoverflow.com/questions/29550736/can-i-mount-docker-host-directory-as-copy-on-write-overlay], I don't want containers to run in privileged mode. Is there a better idea?

Gomo
  • 47
  • 6
  • 1
    You can `COPY --from` files from arbitrary images in your Dockerfiles. The various volume-oriented tricks you see in pure-Docker setups won't work well in Kubernetes; it's hard to get a ReadWriteMany volume, and Kubernetes won't automatically put files into volumes for you. Do you _need_ shared files, or can you use a database or some other mechanism? – David Maze Oct 22 '21 at 16:36
  • Does this work at image build time or at container run time? – Queeg Jan 25 '22 at 21:52

1 Answers1

3

Per design one container cannot access the files inside another container. You will need to store the data outside of a container, then mount it via volume mount or bind mount. Alternatively you could try to perform some NFS/SMB/... mount of shared storage inside the container.

This is completely independent from running a container in host mode.

Queeg
  • 7,748
  • 1
  • 16
  • 42