New container install with a persistent volume, and the app cannot write to its own data directory
I moved a service into a container and mounted a directory from the host so the data survives restarts. The container starts and then fails with permission errors writing to that directory.
If I make the host directory world-writable it works, which tells me it is a permissions problem and also that I have not actually solved it.
What is going on between the host and the container here, and what is the correct fix rather than the one that works?
@containers_koray · 2d ago
The thing to internalise: a bind mount does not translate ownership. The kernel checks numeric IDs, and the container and the host disagree about what those numbers mean.
Inside the container the process might run as a user called
appwith UID 1000. On the host, UID 1000 is your login account, or nobody at all. The directory on the host is owned by some other UID. The kernel compares the numbers, they do not match, and the write is refused.So the name of the user is irrelevant on both sides. Only the number matters.
Find the two numbers and the problem becomes arithmetic:
Once those two agree, it works. Everything below is a way of making them agree.
Reply
Report