summaryrefslogtreecommitdiff
path: root/docker/api
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-10-25 14:30:18 -0700
committerJoffrey F <joffrey@docker.com>2017-10-25 14:30:18 -0700
commitebfbe9a29e4269fa4c7688ca58797540818e3dc8 (patch)
tree1cd7bd44999cfffa6722e8c953d974e4eca29cec /docker/api
parent0d21b5b2549f013889491e02226b5facd758e514 (diff)
downloaddocker-py-build_extra_hosts.tar.gz
Add support for extra_hosts option in buildbuild_extra_hosts
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker/api')
-rw-r--r--docker/api/build.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/docker/api/build.py b/docker/api/build.py
index f9678a3..42a1a29 100644
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -19,7 +19,7 @@ class BuildApiMixin(object):
forcerm=False, dockerfile=None, container_limits=None,
decode=False, buildargs=None, gzip=False, shmsize=None,
labels=None, cache_from=None, target=None, network_mode=None,
- squash=None):
+ squash=None, extra_hosts=None):
"""
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
needs to be set. ``path`` can be a local path (to a directory
@@ -101,6 +101,8 @@ class BuildApiMixin(object):
build
squash (bool): Squash the resulting images layers into a
single layer.
+ extra_hosts (dict): Extra hosts to add to /etc/hosts in building
+ containers, as a mapping of hostname to IP address.
Returns:
A generator for the build output.
@@ -229,6 +231,17 @@ class BuildApiMixin(object):
'squash was only introduced in API version 1.25'
)
+ if extra_hosts is not None:
+ if utils.version_lt(self._version, '1.27'):
+ raise errors.InvalidVersion(
+ 'extra_hosts was only introduced in API version 1.27'
+ )
+
+ encoded_extra_hosts = [
+ '{}:{}'.format(k, v) for k, v in extra_hosts.items()
+ ]
+ params.update({'extrahosts': encoded_extra_hosts})
+
if context is not None:
headers = {'Content-Type': 'application/tar'}
if encoding: