From 8c5cc44946229479135ef24194e970eb504083f5 Mon Sep 17 00:00:00 2001 From: LeoVerto Date: Wed, 1 Jul 2020 15:46:24 +0200 Subject: [PATCH] Fix KeyError when networks with no gateway exist --- docker-net-graph.py | 2 +- test/docker-compose.yml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docker-net-graph.py b/docker-net-graph.py index 44cabc9..bd00804 100755 --- a/docker-net-graph.py +++ b/docker-net-graph.py @@ -63,7 +63,7 @@ def get_networks(client: docker.DockerClient, verbose: bool) -> typing.Dict[str, for net in sorted(client.networks.list(), key=lambda k: k.name): try: - gateway = net.attrs["IPAM"]["Config"][0]["Gateway"] + gateway = net.attrs["IPAM"]["Config"][0]["Subnet"] except (KeyError, IndexError): # This network doesn't seem to be used, skip it continue diff --git a/test/docker-compose.yml b/test/docker-compose.yml index b555eba..e149f32 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -22,6 +22,7 @@ services: - network_a - network_b - network_c + - no_gateway host_service: container_name: host_service image: leoverto/dummy-image @@ -36,3 +37,11 @@ networks: network_b: network_c: empty_network: + no_gateway: + driver: bridge + driver_opts: + com.docker.network.bridge.name: br-no-gateway + ipam: + driver: default + config: + - subnet: 172.22.1.0/24