Skip to content

Commit 6445ed3

Browse files
committed
Add support to DockerEngine
1 parent 4c3e8f4 commit 6445ed3

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

repo2docker/docker.py

Lines changed: 33 additions & 6 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,9 +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-
args = ["docker", "buildx", "build", "--progress", "plain"]
137+
args = [self.cli, "buildx", "build", "--progress", "plain"]
111138
if load:
112139
if push:
113140
raise ValueError(
@@ -164,7 +191,7 @@ def inspect_image(self, image):
164191
Return image configuration if it exists, otherwise None
165192
"""
166193
proc = subprocess.run(
167-
["docker", "image", "inspect", image], capture_output=True
194+
[self.cli, "image", "inspect", image], capture_output=True
168195
)
169196

170197
if proc.returncode != 0:
@@ -193,7 +220,7 @@ def docker_login(self, username, password, registry):
193220
try:
194221
subprocess.run(
195222
[
196-
"docker",
223+
self.cli,
197224
"login",
198225
"--username",
199226
username,

0 commit comments

Comments
 (0)