Why can’t my non-root Docker user access a bind-mounted directory owned by them?

0
2
Asked By CuriousCactus92 On

I'm encountering an issue with Docker where my non-root user can't read or write to a bind-mounted directory that they own. I followed these steps:

1. Built my image using `docker build -t archdevexp .`
2. Created a directory with `mkdir src`
3. Ran my container using `docker run -v $(pwd)/src:/src -it archdevexp bash`
4. Checked the ownership of the `src` directory inside the container, and it showed that it was owned by my user with UID 1000.
5. Inside the container, I ran `id` and confirmed the UID and GID were both 1000.
6. But when I tried to list the contents of `src`, I got a "permission denied" error, and the same for attempting to write in that directory.

I've verified the ownership from the host as well, and everything matches up. My setup includes Fedora Linux 42 running Docker version 28.2.2. I could really use some help figuring out why this is happening! Thanks!

2 Answers

Answered By DockerDude83 On

Have you checked what `docker inspect` reveals about the volumes for your running container? You might also want to try using an absolute path instead of `$(pwd)` just to test if that changes anything. Sometimes, using the actual path helps avoid any path resolution issues.

Answered By QuickFix21 On

It’s possible that the user ID or group ID inside the container doesn’t match what you think. Try running `id` inside the container to verify. In your steps, you mentioned checking this, but double-checking can sometimes reveal discrepancies. It’s a common pitfall!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.