Skip to content

Commit 56afc05

Browse files
committed
Merge pull request #400 from adeslade/create-container-with-extra-hosts
Allow ExtraHosts to be specified when creating a container
2 parents fa61780 + 84fac67 commit 56afc05

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

docker/client.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ def search(self, term):
899899
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
900900
publish_all_ports=False, links=None, privileged=False,
901901
dns=None, dns_search=None, volumes_from=None, network_mode=None,
902-
restart_policy=None, cap_add=None, cap_drop=None, devices=None):
902+
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
903+
extra_hosts=None):
903904
if isinstance(container, dict):
904905
container = container.get('Id')
905906

@@ -932,6 +933,16 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
932933

933934
start_config['Links'] = formatted_links
934935

936+
if extra_hosts:
937+
if isinstance(extra_hosts, dict):
938+
extra_hosts = six.iteritems(extra_hosts)
939+
940+
formatted_extra_hosts = [
941+
'{0}:{1}'.format(k, v) for k, v in sorted(extra_hosts)
942+
]
943+
944+
start_config['ExtraHosts'] = formatted_extra_hosts
945+
935946
start_config['Privileged'] = privileged
936947

937948
if utils.compare_version('1.10', self._version) >= 0:

0 commit comments

Comments
 (0)