Skip to content

Commit c0df903

Browse files
committed
Merge branch 'fix-port-host-net' of https://github.com/ssanderson/docker-py into ssanderson-fix-port-host-net
2 parents 645c84e + 7fae65b commit c0df903

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docker/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,15 @@ def port(self, container, private_port):
733733
s_port = str(private_port)
734734
h_ports = None
735735

736-
h_ports = json_['NetworkSettings']['Ports'].get(s_port + '/udp')
736+
# Port settings is None when the container is running with
737+
# network_mode=host.
738+
port_settings = json_['NetworkSettings']['Ports']
739+
if port_settings is None:
740+
return None
741+
742+
h_ports = port_settings.get(s_port + '/udp')
737743
if h_ports is None:
738-
h_ports = json_['NetworkSettings']['Ports'].get(s_port + '/tcp')
744+
h_ports = port_settings.get(s_port + '/tcp')
739745

740746
return h_ports
741747

0 commit comments

Comments
 (0)