Skip to content

Fix docker based hooks failing on Windows - #1094

Merged
asottile merged 4 commits into
pre-commit:masterfrom
geieredgar:windows-docker-fix
Jul 25, 2019
Merged

Fix docker based hooks failing on Windows#1094
asottile merged 4 commits into
pre-commit:masterfrom
geieredgar:windows-docker-fix

Conversation

@geieredgar

@geieredgar geieredgar commented Jul 23, 2019

Copy link
Copy Markdown
Contributor

Fixes #1072

Docker for Windows

  • mounts the volume passed via -v always using root:root as owner, even if a -u UID:GID option is passed
  • newly created files (e.g. via touch) also use root:root as owner, even if the container is run as non-root user
  • read/write access is also provided to non-root users, even if ls -l yields -rwxr-x-r-x as file permissions
  • files created inside the container appear on the host as if they were created by the user running the docker command

This is because Docker for Windows currently implements host mounted volumes via SMB (see https://docs.docker.com/docker-for-windows/troubleshoot/#volumes), which handles the access to mounted files and does not allow changing permissions from inside the container (see docker/docs#3298).

Therefore the UID and GID we pass to docker can be chosen arbitrarily, because the owner of files on the host will match the Windows user running docker and not the user in the docker container.

There are also some other caveats when it comes to running linux docker images via Docker for Windows, e.g. you have to be careful about line endings (moby/moby#24388).

With these changes I was able to successfully run a hook on Windows using language: docker_image for a personal project of mine, therefore I would like to see something like this getting merged.

What are your thoughts about this?

@geieredgar geieredgar changed the title Use fallback uid and gid if os.getuid() and os.getgid() are unavailable Fix docker based hooks failing on Windows Jul 23, 2019
@geieredgar
geieredgar marked this pull request as ready for review July 23, 2019 13:53

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my, I forgot to press submit -- so sorry on the delay here

Comment thread pre_commit/languages/docker.py Outdated
Comment thread tests/languages/docker_test.py Outdated

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile
asottile merged commit 376d283 into pre-commit:master Jul 25, 2019
@asottile

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Docker language fails on Windows - os.getuid()

2 participants