gitdockeruser-rolespasswdetcpasswd

How can you run a GIT container as the current user?


I want to use GIT from within a Docker container. The usage as documented on https://hub.docker.com/r/alpine/git/ is quite simple:

docker run -it --rm -v ${HOME}:/root -v $(pwd):/git alpine/git clone ...

This works. One big downside of this is that all files are now owned by root, instead of the current user. I wanted to solve this, but am failing so far.

My current command is:

docker run -it --rm
       --user $(id -u):$(id -g)
       -v $HOME:$HOME:rw
       -v /etc/passwd:/etc/paswd:ro
       -v /etc/group:/etc/group:ro
       -v $PWD:$PWD:rw
       -w $PWD
       alpine/git
       clone ...

Here, I pass --user $(id -u):$(id -g) to run as the current user. Also, I am passing $HOME, /etc/passwd and /etc/group to allow the container to resolve the current user and the home directory.

This gives the following error: No user exists for uid 1000. Where does this come from and how can it be solved?

Version information: docker run -it --rm alpine/git --version gives git version 2.15.0


Solution

  • This is quite embarrassing. I had a typo, as pointed out by @torek in the comments. It should have been:

    docker run -it --rm
           --user $(id -u):$(id -g)
           -v $HOME:$HOME:rw
           -v /etc/passwd:/etc/passwd:ro
           -v /etc/group:/etc/group:ro
           -v $PWD:$PWD:rw
           -w $PWD
           alpine/git
           clone ...
    

    This works as expected!