Question:
I am making a Docker image. I would like to have a ready-made environment in there as well as some ready-made directories. In this way, I only need to mount some of my directories and use them directly. I made the image using the Dockerfile below. In order to have the same permissions inside and outside the container (not root), I created auser
user.What I think is that the inside and outside of the gem5 directory should be exactly the same user. But it’s not.
docker
user, and all other directories are user
.
I am able to create files inside my mounted directory. But for gem5’s directory, I don’t even have permission to create files.
But according to the Dockfile, I have clearly chown this directory to user
. And when entering the container, I set the uid
.FileNotFoundError: [Errno 2] No such file or directory: "/usr/local/src/gem5/fatal: unsafe repository ('/usr/local/src/gem5' is owned by someone else)\nTo add an exception for this directory, call:\n\n\tgit config --global --add safe.directory /usr/local/src/gem5/hooks"
:Answer:
As the question was tagged with podman (in addition to docker), here is a Podman solution to the problem of mapping users between the host and the container:If you want to map your regular user on the host to a user with the same UID inside the container, you could add the Podman option
--userns=keep-id
. A more general solution (that also works when the UIDs are not the same) can be found in the troubleshooting.md tip and tip. The tips make use of the options –uidmap and –gidmap. (I wrote those tips).The two options –uidmap and –gidmap may look to be a bit complicated to use, but as soon as you understand how rootless Podman maps UIDs and GIDs it will be pretty straight forward.
If you have better answer, please add a comment about this, thank you!