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
parent 657363e011
commit 9db5ac8e45

View file

@ -1062,7 +1062,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))