Allow passing in extra args to Docker initialization

Puts it in the ContainerEngine interface specific to Docker,
so PodMan can implement its own when necessary.

Fixes https://github.com/jupyterhub/repo2docker/issues/711
pull/1124/head
YuviPanda 2022-01-26 16:16:46 +05:30
rodzic e3d0a9ae8e
commit 3af38557ad
1 zmienionych plików z 18 dodań i 3 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ Docker container engine for repo2docker
"""
import docker
from traitlets import Dict
from iso8601 import parse_date
from .engine import Container, ContainerEngine, ContainerEngineException, Image
@ -53,12 +54,26 @@ class DockerEngine(ContainerEngine):
string_output = False
extra_init_args = Dict(
{},
help="""
Extra kwargs to pass to docker client when initializing it.
Dictionary that allows users to specify extra parameters to pass
to APIClient, parameters listed in https://docker-py.readthedocs.io/en/stable/api.html#docker.api.client.APIClient.
Parameters here are merged with whatever is picked up from the
environment.
""",
config=True,
)
def __init__(self, *, parent):
super().__init__(parent=parent)
try:
self._apiclient = docker.APIClient(
version="auto", **docker.utils.kwargs_from_env()
)
kwargs = docker.utils.kwargs_from_env()
kwargs.update(self.extra_init_args)
self._apiclient = docker.APIClient(version="auto", **kwargs)
except docker.errors.DockerException as e:
raise ContainerEngineException("Check if docker is running on the host.", e)