Skip to content

Commit b8a2c88

Browse files
authored
Merge pull request #1124 from yuvipanda/extra-args
Allow passing in extra args to Docker initialization
2 parents 7f89926 + a5df995 commit b8a2c88

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

repo2docker/docker.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import docker
6+
from traitlets import Dict
67
from iso8601 import parse_date
78

89
from .engine import Container, ContainerEngine, ContainerEngineException, Image
@@ -53,12 +54,27 @@ class DockerEngine(ContainerEngine):
5354

5455
string_output = False
5556

57+
extra_init_args = Dict(
58+
{},
59+
help="""
60+
Extra kwargs to pass to docker client when initializing it.
61+
62+
Dictionary that allows users to specify extra parameters to pass
63+
to APIClient, parameters listed in https://docker-py.readthedocs.io/en/stable/api.html#docker.api.client.APIClient.
64+
65+
Parameters here are merged with whatever is picked up from the
66+
environment.
67+
""",
68+
config=True,
69+
)
70+
5671
def __init__(self, *, parent):
5772
super().__init__(parent=parent)
5873
try:
59-
self._apiclient = docker.APIClient(
60-
version="auto", **docker.utils.kwargs_from_env()
61-
)
74+
kwargs = docker.utils.kwargs_from_env()
75+
kwargs.update(self.extra_init_args)
76+
kwargs.setdefault("version", "auto")
77+
self._apiclient = docker.APIClient(**kwargs)
6278
except docker.errors.DockerException as e:
6379
raise ContainerEngineException("Check if docker is running on the host.", e)
6480

0 commit comments

Comments
 (0)