A container cannot read or write a mounted host folder
Permission denied on accessing host directory in DockerShort answer
When a bind-mounted host folder is denied inside the container, look at two documented causes first: SELinux on Fedora, RHEL and similar systems blocks the container until the mount carries a :z or :Z label, and a mount flagged ro or readonly can never be written. Fix the flag, then retest.
Fix it fast
1Find out which cause you have
Print how the mount is configured. Look for a read-only flag, then check whether SELinux is enforcing.
docker inspect --format '{{ json .Mounts }}' my-container getenforce2Match what you see, then jump to its fix
What does the error look like?
Permission denied on accessing host directory in DockerFiles in the mounted folder cannot be listed or opened from inside the containerWrites to the mounted folder fail while the same folder works on the host
Cause 1 of 2
SELinux blocks the container from the host directory
1Check
SELinux is common on Fedora, RHEL, Rocky and Alma. Docker documents labels for bind mounts: z marks the content as shared among containers, Z as private to one.
getenforce2Fix
Add the z label if several containers share the folder, or Z if only this container uses it. Use extreme caution: the label changes the host directory itself, so do not label system folders such as your home directory.
docker run -d --name devtest \
-v "$(pwd)"/target:/app:z \
nginx:latest3Verify
List the folder from inside the container.
docker exec devtest ls -l /appConfirmed by docs.docker.com
Cause 2 of 2
The mount is read-only
1Check
Docker lets you mount a bind mount read-only with the readonly or ro option. Search the run command and the compose file for it.
grep -n -E ':ro|readonly|read_only' compose.yaml2Fix
Remove :ro or the readonly option if the container must write, and recreate the container.
# before
-v "$(pwd)"/target:/app:ro
# after
-v "$(pwd)"/target:/app3Verify
A test file can be created from inside.
docker exec my-container touch /app/test.txtConfirmed by docs.docker.com
How do I stop it coming back?
- On SELinux systems add :z or :Z to every bind mount in your run commands and compose files.
- Use :ro only on mounts that the container must never change, such as config files.
- Never relabel broad host folders such as your home directory or /etc.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix