Skip to content

Commit 8f1a82f

Browse files
author
John Howard
committed
Add netmode (required by docker)
Signed-off-by: John Howard <[email protected]>
1 parent f8ad2da commit 8f1a82f

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

docker/utils/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ def create_container_config(
615615
if volumes_from is not None:
616616
raise errors.InvalidVersion(message.format('volumes_from'))
617617

618+
# NetworkMode must be present and valid in host config from 1.20 onwards
619+
if compare_version('1.20', version) >= 0:
620+
if host_config is None:
621+
host_config = {'NetworkMode': 'default'}
622+
else:
623+
if 'NetworkMode' not in host_config:
624+
host_config['NetworkMode'] = 'default'
625+
elif host_config['NetworkMode'] == '':
626+
host_config['NetworkMode'] = 'default'
627+
618628
return {
619629
'Hostname': hostname,
620630
'Domainname': domainname,

tests/integration_test.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def runTest(self):
181181
container = self.client.create_container(
182182
'busybox',
183183
['ls', mount_dest], volumes={mount_dest: {}},
184-
host_config=create_host_config(binds=binds)
184+
host_config=create_host_config(
185+
binds=binds, network_mode='none')
185186
)
186187
container_id = container['Id']
187188
self.client.start(container_id)
@@ -221,7 +222,8 @@ def runTest(self):
221222
container = self.client.create_container(
222223
'busybox',
223224
['ls', mount_dest], volumes={mount_dest: {}},
224-
host_config=create_host_config(binds=binds)
225+
host_config=create_host_config(
226+
binds=binds, network_mode='none')
225227
)
226228
container_id = container['Id']
227229
self.client.start(container_id)
@@ -273,7 +275,8 @@ class TestCreateContainerReadOnlyFs(BaseTestCase):
273275
def runTest(self):
274276
ctnr = self.client.create_container(
275277
'busybox', ['mkdir', '/shrine'],
276-
host_config=create_host_config(read_only=True)
278+
host_config=create_host_config(
279+
read_only=True, network_mode='none')
277280
)
278281
self.assertIn('Id', ctnr)
279282
self.tmp_containers.append(ctnr['Id'])
@@ -347,7 +350,8 @@ def runTest(self):
347350
class TestCreateContainerPrivileged(BaseTestCase):
348351
def runTest(self):
349352
res = self.client.create_container(
350-
'busybox', 'true', host_config=create_host_config(privileged=True)
353+
'busybox', 'true', host_config=create_host_config(
354+
privileged=True, network_mode='none')
351355
)
352356
self.assertIn('Id', res)
353357
self.tmp_containers.append(res['Id'])
@@ -591,7 +595,8 @@ def runTest(self):
591595

592596
container = self.client.create_container(
593597
'busybox', ['sleep', '60'], ports=list(port_bindings.keys()),
594-
host_config=create_host_config(port_bindings=port_bindings)
598+
host_config=create_host_config(
599+
port_bindings=port_bindings, network_mode='bridge')
595600
)
596601
id = container['Id']
597602

@@ -717,7 +722,8 @@ def runTest(self):
717722
)
718723
res2 = self.client.create_container(
719724
'busybox', 'cat', detach=True, stdin_open=True,
720-
host_config=create_host_config(volumes_from=vol_names)
725+
host_config=create_host_config(
726+
volumes_from=vol_names, network_mode='none')
721727
)
722728
container3_id = res2['Id']
723729
self.tmp_containers.append(container3_id)
@@ -760,7 +766,8 @@ def runTest(self):
760766

761767
res2 = self.client.create_container(
762768
'busybox', 'env', host_config=create_host_config(
763-
links={link_path1: link_alias1, link_path2: link_alias2}
769+
links={link_path1: link_alias1, link_path2: link_alias2},
770+
network_mode='none'
764771
)
765772
)
766773
container3_id = res2['Id']
@@ -781,7 +788,8 @@ class TestRestartingContainer(BaseTestCase):
781788
def runTest(self):
782789
container = self.client.create_container(
783790
'busybox', ['sleep', '2'], host_config=create_host_config(
784-
restart_policy={"Name": "always", "MaximumRetryCount": 0}
791+
restart_policy={"Name": "always", "MaximumRetryCount": 0},
792+
network_mode='none'
785793
)
786794
)
787795
id = container['Id']
@@ -910,7 +918,7 @@ class TestCreateContainerWithHostPidMode(BaseTestCase):
910918
def runTest(self):
911919
ctnr = self.client.create_container(
912920
'busybox', 'true', host_config=create_host_config(
913-
pid_mode='host'
921+
pid_mode='host', network_mode='none'
914922
)
915923
)
916924
self.assertIn('Id', ctnr)
@@ -945,7 +953,7 @@ def runTest(self):
945953

946954
container2 = self.client.create_container(
947955
'busybox', 'cat', host_config=create_host_config(
948-
links={link_path: link_alias}
956+
links={link_path: link_alias}, network_mode='none'
949957
)
950958
)
951959
container2_id = container2['Id']

0 commit comments

Comments
 (0)