When starting a container and specifying a volume you can optionally append a third field that's a comma separated list of options like rw
.
docker run -v /some-host/path:/some-container/path:rw
This same options are applicable in the docker.compose.yml
services:
myService:
image: some/image
volumes:
- /some-host/path:/some-container/path:rw
I thought that specifing rw
would mean that the container would be able to read from and write to that directory (regardless of user). Contrary to my belief, when the host directory doesn't exist, docker creates it as drwxr-xr-x 2 root root
no matter what I specify. The application in the container is not running on root
though, so it tries to write to the mounted drive and get's Permission denied
.
I've dug through the docker documents, even found this github issue describing the same issue, but can't find anything definitive that explains expected behavior.
So what exactly does rw
(read/write) mean when specified as a third option for bind mounted directories?
/
on your host is mounted read-write but isn’t world-writable on every file; if it were mounted read-only nobody could write any file.