linuxdockerubuntuuser-permissionsdocker-desktop

How can I map user ids from host to container using docker desktop?


I am using docker desktop on ubuntu to start and run containers with docker compose.

There is a user id mismatch between host and container which is causing permission issues.

My application is based on this example (the dockerfile is the same) - https://github.com/nickjj/docker-rails-example/blob/main/Dockerfile

At build time it creates a 'ruby' user with uid:gid of 1000:1000. This matches my host id:gid. This worked nicely on my old laptop, but on my new one it seems files owned by the host user appear as owned by root in the container.

When I try chown as the ruby user the files appear as being owned by someone else:

-rw-rw-r-- 1 100999 100999 8318 Nov 22 20:26 README.md

Somewhere the mapping between host and container is not being made. From what I've gathered there are user name space remapping features but these aren't available when using docker desktop. What options are available?


Solution

  • At the moment, I do not have all the details, I just started to use Docker Desktop for Linux recently. But I found a ticket at https://github.com/docker/desktop-linux/issues/31 that explains the situation in detail. Most of the information I add here comes from the discussion in that link, especially from the answers by p1-0tr. In summary: