Reputation: 7908
I have two volumes: repo
and cache
. I want to mount repo
read-only at /repo
and I want to mount cache
as read-write at /repo/cache
. When the app writes to /repo/cache
, I expect the writes to go to the cache
volume, while the /repo
volume is not changed; however, when I run docker run -it -v repo:/repo:ro -v cache:/repo/cache alpine
, I get docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/volumes/cache/_data\\\" to rootfs \\\"/var/lib/docker/overlay2/9f1dfff7f943921fd2da278d357bec88007d7fcb41eb9bc34fc0e728c459ad73/merged\\\" at \\\"/var/lib/docker/overlay2/9f1dfff7f943921fd2da278d357bec88007d7fcb41eb9bc34fc0e728c459ad73/merged/repo/cache\\\" caused \\\"mkdir /var/lib/docker/overlay2/9f1dfff7f943921fd2da278d357bec88007d7fcb41eb9bc34fc0e728c459ad73/merged/repo/cache: read-only file system\\\"\"": unknown.
Is there a better way to achieve this result? I need the repo
volume to be ro
so the app doesn't write to it, and I need cache
to be writable and mounted "inside" of /repo
because that's where the app expects it (and I can't modify the app to look elsewhere).
Upvotes: 0
Views: 1307
Reputation: 311635
To mount your cache
volume on /repo/cache
, Docker would need to be able to create a directory /repo/cache
inside the container. Since you have mounted the repo
volume read-only, this isn't possible.
If you first create the mountpoint yourself:
docker run --rm -v repo:/repo alpine mkdir /repo/cache
Then you will be able to successfully mount /repo/cache
despite repo
being read-only:
bash-5.0$ docker run --rm -it -v repo:/repo:ro -v cache:/repo/cache alpine
/ # ls /repo
cache
Upvotes: 4