Create docker client from standard env vars

This commit is contained in:
Einar Forselv 2019-12-16 22:19:57 +01:00
parent d002ad9390
commit cab4676b91
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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]: