Don't assume ExposedPorts exists (bug #2257)

A recent change [1] in docker between v1.8.2 and v1.8.3 changed what
is returned in the json when inspecting an image. Five variables which
could have been expected before will now be omited when empty. Only
one of those variables is being addressed in the docker, ExposedPorts.

Unfortunately there was also no API version change on this so this
can't be easily corrected with pinning the API to the older version.

This does a get() which will return None if the variable is not in the
dict formed from the json that was returned. Everything else works the
same way.

[1] 9098628b29
This commit is contained in:
Sam Yaple 2015-10-13 10:24:36 +00:00 committed by Matt Clay
parent 183430628b
commit 463fb5a058

View file

@ -1067,7 +1067,7 @@ class DockerManager(object):
continue continue
# EXPOSED PORTS # EXPOSED PORTS
expected_exposed_ports = set((image['ContainerConfig']['ExposedPorts'] or {}).keys()) expected_exposed_ports = set((image['ContainerConfig'].get('ExposedPorts') or {}).keys())
for p in (self.exposed_ports or []): for p in (self.exposed_ports or []):
expected_exposed_ports.add("/".join(p)) expected_exposed_ports.add("/".join(p))