How to handle host permissions when mounting files into containers

Hey all,

We’re running into a weird host specific issue when running our docker containers through docker-compose in our team and I was wondering if anyone had any input or advice.

The Issue

When mounting files, the docker daemon seems to understand and transfer the permissions (uid and gid) from the host machine to the docker container. Like most docker images, the base docker image defines a user of uid/gid 1000 in its Dockerfile. So, when team members that have uid/gid of 1000 for their host user run docker-compose, the docker container recognizes that user 1000 and automatically says, “Ah, the mounted files are owned by my uid 1000 that I know about!” This makes sense and is pretty helpful.

Then when users with non 1000 uids run docker-compose, their mounted files are owned by root, because the docker container cannot associated their uid 501 with the docker containers 1000 uid user.

This is leading to weird permission issues for some of the users and not others. Mostly, it affects the 1000 uid users because some commands are run as root and others as uid 1000, so the permissions are split between those two users.

The issue is only happening when mounting. Because that is when the uid of 1000 is being introduced for some users. If there are no mounts, it seems to work fine. But rebuilding on dev changes isn’t super practical.

Any ideas on how to solve this without having the team members resort to changing their host machine user ids or file permissions?

Thanks!