currently this is how pre-commit checks if docker is available:
|
def docker_is_running() -> bool: # pragma: win32 no cover |
|
try: |
|
cmd_output_b('docker', 'ps') |
|
except CalledProcessError: |
|
return False |
|
else: |
|
return True |
|
|
|
|
|
def assert_docker_available() -> None: # pragma: win32 no cover |
|
assert docker_is_running(), ( |
|
'Docker is either not running or not configured in this environment' |
|
) |
there's two low-hanging-fruit problems with this:
- it is checked repeatedly, but can probably be checked just once per process (can use
functools.lru_cache as a "run once" decorator)
docker ps is pretty slow, there's probably a faster way to see if docker is available -- on my machine it takes more than a second! even without containers
$ time docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
real 0m1.169s
user 0m0.088s
sys 0m0.085s
currently this is how pre-commit checks if docker is available:
pre-commit/pre_commit/languages/docker.py
Lines 29 to 41 in 9a5461d
there's two low-hanging-fruit problems with this:
functools.lru_cacheas a "run once" decorator)docker psis pretty slow, there's probably a faster way to see if docker is available -- on my machine it takes more than a second! even without containers