From cab4676b91e5f6498ceb64d1737ee71d4d156885 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Mon, 16 Dec 2019 22:19:57 +0100 Subject: [PATCH] Create docker client from standard env vars --- src/restic_compose_backup/config.py | 1 - src/restic_compose_backup/utils.py | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/restic_compose_backup/config.py b/src/restic_compose_backup/config.py index 76968e7..1795f5c 100644 --- a/src/restic_compose_backup/config.py +++ b/src/restic_compose_backup/config.py @@ -10,7 +10,6 @@ class Config: # Mandatory values self.repository = os.environ.get('RESTIC_REPOSITORY') self.password = os.environ.get('RESTIC_REPOSITORY') - self.docker_base_url = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock" self.cron_schedule = os.environ.get('CRON_SCHEDULE') or self.default_crontab_schedule self.cron_command = os.environ.get('CRON_COMMAND') or self.default_backup_command diff --git a/src/restic_compose_backup/utils.py b/src/restic_compose_backup/utils.py index b03c71d..66c1cd0 100644 --- a/src/restic_compose_backup/utils.py +++ b/src/restic_compose_backup/utils.py @@ -11,8 +11,18 @@ TRUE_VALUES = ['1', 'true', 'True', True, 1] def docker_client(): - config = Config() - return docker.DockerClient(base_url=config.docker_base_url) + """ + Create a docker client from the following environment variables:: + + DOCKER_HOST=unix://tmp/docker.sock + DOCKER_TLS_VERIFY=1 + DOCKER_CERT_PATH='' + """ + # NOTE: Remove this fallback in 1.0 + if not os.environ.get('DOCKER_HOST'): + os.environ['DOCKER_HOST'] = 'unix://tmp/docker.sock' + + return docker.from_env() def list_containers() -> List[dict]: