Skip to content

Commit

Permalink
dockerctl: use 'podman' if present and 'docker version' fails
Browse files Browse the repository at this point in the history
`podman` is an almost-CLI-compatible replacement for `docker`, which
allows unprivileged users to run containers, with no daemon. On some
systems, `docker` is a symbolic link to `podman`.

I say "almost" because one command that is not compatible is `docker
version --format '{{ json . }}'`, used by Karton to detect whether
docker is present and usable.
containers/podman#2671

To work around this, if _try_docker() fails, but running `podman
version` succeeds, use `podman` instead. Otherwise, behave as before.
  • Loading branch information
wjt committed Mar 15, 2019
1 parent 5a9c46a commit 0771135
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions karton/dockerctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ def __init__(self):
# Another, unexpected, error happened while trying to use a Docker command.
_DOCKER_OTHER_ERROR = 10

def _can_use_podman(self):
'''
Try running Podman to check its availability.
Return value:
True if Podman is available; False otherwise.
'''
try:
proc.check_output(
['podman', 'version'],
stderr=proc.DEVNULL)
except OSError as exc:
return False
else:
return True

def _try_docker(self):
'''
Try running Docker to check its availability.
Expand Down Expand Up @@ -141,6 +158,11 @@ def _ensure_docker(self):
if status == self._DOCKER_SUCCESS:
return

elif self._can_use_podman():
verbose("Found 'podman'; using it instead of docker");
self._docker_command = ['podman']
return self._DOCKER_SUCCESS

elif status == self._DOCKER_NO_COMMAND:
if sys.platform == 'darwin':
install_url = 'https://docs.docker.com/docker-for-mac/install/'
Expand Down

0 comments on commit 0771135

Please sign in to comment.