diff --git a/README.md b/README.md index 19b6ca0..e64b817 100644 --- a/README.md +++ b/README.md @@ -52,4 +52,4 @@ command as if you were running it in a local shell. If you'd like to contribute to this project, there is a sample docker-compose file using dummy containers in `test`. -You can deploy it using `docker-compose -f test/docker-compose.yml up -d` +You can deploy it using `docker-compose -f test/docker-compose.yml up -d`. diff --git a/docker-net-graph.py b/docker-net-graph.py index 77a04e9..44cabc9 100755 --- a/docker-net-graph.py +++ b/docker-net-graph.py @@ -28,6 +28,7 @@ class Network: class Interface: endpoint_id: str address: str + aliases: typing.List[str] @dataclass @@ -103,7 +104,14 @@ def get_containers(client: docker.DockerClient, verbose: bool) -> (typing.List[C for net_name, net_info in container.attrs["NetworkSettings"]["Networks"].items(): endpoint_id = net_info["EndpointID"] - interfaces.append(Interface(endpoint_id, net_info['IPAddress'])) + aliases = [] + if net_info["Aliases"]: + for alias in net_info["Aliases"]: + # The aliases always contain the shortened container id and container name + if alias != container.id[:12] and alias != container.name: + aliases.append(alias) + + interfaces.append(Interface(endpoint_id, net_info['IPAddress'], aliases)) links.append(Link(container.id, endpoint_id, net_name)) if verbose: @@ -131,9 +139,18 @@ def draw_network(g: Graph, net: Network): def draw_container(g: Graph, c: Container): - iface_labels = [f"<{iface.endpoint_id}> {iface.address}" for iface in c.interfaces] + iface_labels = [] - label = f"{{ {c.name} | {{ {'|'.join(iface_labels)} }} }}" + for iface in c.interfaces: + iface_label = "{" + + for alias in iface.aliases: + iface_label += f" {alias} |" + + iface_label += f"<{iface.endpoint_id}> {iface.address} }}" + iface_labels.append(iface_label) + + label = f"{{ {c.name} | {{ {' | '.join(iface_labels)} }} }}" g.node(f"container_{c.container_id}", shape="record", diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 108e4e1..b555eba 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -11,8 +11,10 @@ services: container_name: service_2 image: leoverto/dummy-image networks: - - network_b - - network_c + network_b: + network_c: + aliases: + - "s2.netc" service_3: container_name: service_3 image: leoverto/dummy-image