Skip to content

Commit 1beb2a9

Browse files
committed
Add support to DockerEngine
1 parent 703a864 commit 1beb2a9

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

repo2docker/docker.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pathlib import Path
1414

1515
from iso8601 import parse_date
16-
from traitlets import Dict, List, Unicode
16+
from traitlets import Dict, List, Unicode, default
1717

1818
import docker
1919

@@ -66,6 +66,35 @@ class DockerEngine(ContainerEngine):
6666

6767
string_output = True
6868

69+
cli = Unicode(
70+
"",
71+
help="""
72+
The commandline for Docker.
73+
""",
74+
config=True,
75+
)
76+
77+
@default("cli")
78+
def _default_cli(self):
79+
for cli in ["docker", "podman"]:
80+
docker_version = subprocess.run([cli, "version"])
81+
if docker_version.returncode == 0:
82+
docker_cli = cli
83+
break
84+
else:
85+
raise RuntimeError("The docker or podman commandline client must be installed")
86+
87+
# docker buildx is based in a plugin that might not be installed
88+
# https://github.com/docker/buildx
89+
#
90+
# podman buildx command is an alias of podman build.
91+
# Not all buildx build features are available in Podman.
92+
docker_buildx_version = subprocess.run([docker_cli, "buildx", "version"])
93+
if docker_buildx_version.returncode:
94+
raise RuntimeError("The docker buildx plugin must be installed")
95+
96+
return docker_cli
97+
6998
extra_init_args = Dict(
7099
{},
71100
help="""
@@ -105,16 +134,7 @@ def build(
105134
platform=None,
106135
**kwargs,
107136
):
108-
if not shutil.which("docker"):
109-
raise RuntimeError("The docker commandline client must be installed")
110-
111-
# docker buildx is based in a plugin that might not be installed
112-
# https://github.com/docker/buildx
113-
docker_buildx_version = subprocess.run(["docker", "buildx", "version"])
114-
if docker_buildx_version.returncode:
115-
raise RuntimeError("The docker buildx plugin must be installed")
116-
117-
args = ["docker", "buildx", "build", "--progress", "plain"]
137+
args = [self.cli, "buildx", "build", "--progress", "plain"]
118138
if load:
119139
if push:
120140
raise ValueError(
@@ -171,7 +191,7 @@ def inspect_image(self, image):
171191
Return image configuration if it exists, otherwise None
172192
"""
173193
proc = subprocess.run(
174-
["docker", "image", "inspect", image], capture_output=True
194+
[self.cli, "image", "inspect", image], capture_output=True
175195
)
176196

177197
if proc.returncode != 0:
@@ -200,7 +220,7 @@ def docker_login(self, username, password, registry):
200220
try:
201221
subprocess.run(
202222
[
203-
"docker",
223+
self.cli,
204224
"login",
205225
"--username",
206226
username,

0 commit comments

Comments
 (0)