9

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

  • Did you create an additional user inside your Container? The user from the host computer running the Docker Container is not visible from inside the container. You would need to create a user inside the container first. – benhorgen Jan 02 '19 at 14:08
  • I hoped to be able to avoid that by passing `$HOME`, `/etc/passwd` and `/etc/group`. I hoped that was sufficient. What would manually creating a user provide additionally? –  Jan 02 '19 at 14:10
  • 1
    I don't have the issue you described. On ubuntu 18.04 – Siyu Jan 02 '19 at 14:12
  • 3
    You have a typo (`/etc/paswd` with one S); but there's no guarantee that these files suffice (some systems use password databases). It's not clear where the "No user exists for ..." message is coming from. It's also not clear whether `-v` allows files at all—the description in the `docker run` documentation refers to directories, not files. – torek Jan 02 '19 at 14:13
  • @torek Oh my... The typo was indeed the error here. Thanks, appreciated! –  Jan 02 '19 at 14:17

1 Answers1

6

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!

  • 1
    Well, I guess it does allow files, and they suffice. :-) – torek Jan 02 '19 at 14:17
  • Yeah, `-v` can be used for files. Also, in most typical cases in which you derive from the `alpine` base image, passing `/etc/passwd` worked fine for me. –  Jan 02 '19 at 14:18
  • 1
    @torek I just realized that it might have been impolite to post my own answer. If you prefer, feel free to answer and I will accept yours as accepted. –  Jan 02 '19 at 14:21
  • 2
    No, that's fine. I learned that docker will mount files, not just directories! :-) – torek Jan 02 '19 at 14:24