Fix KeyError when networks with no gateway exist

This commit is contained in:
LeoVerto 2020-07-01 15:46:24 +02:00
parent 23112d8e39
commit 8c5cc44946
2 changed files with 10 additions and 1 deletions

View file

@ -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

View file

@ -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