Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect rootless mode #1484

Closed
wants to merge 11 commits into from
12 changes: 12 additions & 0 deletions pre_commit/languages/docker.py
@@ -1,5 +1,6 @@
import hashlib
import os
import subprocess
from typing import Sequence
from typing import Tuple

Expand Down Expand Up @@ -77,7 +78,18 @@ def install_environment(


def get_docker_user() -> Tuple[str, ...]: # pragma: win32 no cover
output = subprocess.check_output(
('docker', 'system', 'info'),
text=True,
)
try:
for line in output.splitlines():
# rootless docker has "rootless"
# rootless podman has "rootless: true"
if line.strip().startswith('rootless'):
if 'false' not in line:
return () # no -u for rootless
break
themr0c marked this conversation as resolved.
Show resolved Hide resolved
return ('-u', f'{os.getuid()}:{os.getgid()}')
except AttributeError:
return ()
Expand Down