Skip to content
12 changes: 12 additions & 0 deletions pre_commit/languages/docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import os
import subprocess
from typing import Sequence
from typing import Tuple

Expand Down Expand Up @@ -78,6 +79,17 @@ def install_environment(

def get_docker_user() -> Tuple[str, ...]: # pragma: win32 no cover
try:
output = subprocess.check_output(
Comment thread
themr0c marked this conversation as resolved.
Outdated
('docker', 'system', 'info'),
text=True,
)
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
Comment thread
themr0c marked this conversation as resolved.
Outdated
return ('-u', f'{os.getuid()}:{os.getgid()}')
except AttributeError:
return ()
Expand Down