Skip to content

Instantly share code, notes, and snippets.

@RichVRed
Created December 7, 2016 19:24
Show Gist options
  • Select an option

  • Save RichVRed/225985abb6218316fa6fdcfec19847f6 to your computer and use it in GitHub Desktop.

Select an option

Save RichVRed/225985abb6218316fa6fdcfec19847f6 to your computer and use it in GitHub Desktop.
Git trick for building docker images
# source: https://github.com/docker/docker/issues/7198#issuecomment-200964423
As discussed above, when sharing content from your home folder into a container, add a user account with the same UID as yours. Here's a trick to cope if your UID isn't 1000. I assume that each user builds his own docker image from the Dockerfile.
Your Dockerfile should contain:
RUN useradd --uid 1000 -m vagrant
USER vagrant
The constant 1000 is substituted for your actual UID using a git filter. Run the following on your host:
git config filter.uidfix.smudge "sed s/1000/$UID/g"
git config filter.uidfix.clean "sed s/$UID/1000/g"
Finally, add a .gitattributes file to apply the git filter:
Dockerfile filter=uidfix
This works by replacing 1000 with your actual UID when you checkout the Dockerfile by smudging the file. Git will clean the file (putting back 1000) when you commit. Any commands run in the container run as vagrant user with the correct UID.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment