Skip to content

Instantly share code, notes, and snippets.

@haboustak
Last active April 23, 2020 09:23
Show Gist options
  • Save haboustak/01366dc9af8bb2f2cae8eb5b3edad842 to your computer and use it in GitHub Desktop.
Save haboustak/01366dc9af8bb2f2cae8eb5b3edad842 to your computer and use it in GitHub Desktop.
Proposed docker-py EndpointConfig
mike@dev:~/projects/docker-py$ git diff
diff --git a/docker/models/containers.py b/docker/models/containers.py
index d1f275f..535b3c0 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -973,6 +973,7 @@ RUN_CREATE_KWARGS = [
'use_config_proxy',
'user',
'working_dir',
+ 'networking_config',
]
# kwargs to copy straight from run to host_config
diff --git a/docker/types/networks.py b/docker/types/networks.py
index 1c7b2c9..f615284 100644
--- a/docker/types/networks.py
+++ b/docker/types/networks.py
@@ -4,7 +4,7 @@ from ..utils import normalize_links, version_lt
class EndpointConfig(dict):
def __init__(self, version, aliases=None, links=None, ipv4_address=None,
- ipv6_address=None, link_local_ips=None):
+ ipv6_address=None, link_local_ips=None, driver_opt=None):
if version_lt(version, '1.22'):
raise errors.InvalidVersion(
'Endpoint config is not supported for API version < 1.22'
@@ -33,6 +33,11 @@ class EndpointConfig(dict):
if ipam_config:
self['IPAMConfig'] = ipam_config
+ if driver_opt:
+ if not isinstance(driver_opt, dict):
+ raise TypeError('driver_opt must be a dictionary')
+
+ self['DriverOpts'] = driver_opt
class NetworkingConfig(dict):
def __init__(self, endpoints_config=None):
import docker
client = docker.from_env()
debian = client.containers.create(
image="debian:9",
command="/bin/sh",
tty=True,
detach=True,
networking_config=client.api.create_networking_config({
'testnet': client.api.create_endpoint_config(
driver_opt={ 'com.ccsw.veth.link': '12345' }
),
})
)
debian.start()
print(debian.id)
debian.kill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment