Compare commits

..

No commits in common. "c0035c2b899903696f599a7d00fc035521f3d09c" and "84387e105d4fa40d2fa84586acef5975a2102d93" have entirely different histories.

2 changed files with 9 additions and 19 deletions

View file

@ -3,7 +3,7 @@
Visualize the relationship between Docker networks and containers Visualize the relationship between Docker networks and containers
as a neat graphviz graph. as a neat graphviz graph.
This repository fork [MuratovAS/docker-network-graph](https://github.com/MuratovAS/docker-network-graph) This repository fork [e-dant/docker-network-graph](https://github.com/e-dant/docker-network-graph)
Changes: Changes:
- Improved design - Improved design
- Added the ability to generate url - Added the ability to generate url
@ -30,18 +30,7 @@ If you want to generate a graph for a remote system you can also easily
run this script inside a pre-built docker container: run this script inside a pre-built docker container:
```bash ```bash
build container docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/muratovas/docker-network-graph:latest -u
docker build . -t code.brothertec.eu/simono41/docker-network-graph:latest
and create a PNG
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock code.brothertec.eu/simono41/docker-network-graph:latest | dot -Tpng -o out.png
or as SVG
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock code.brothertec.eu/simono41/docker-network-graph:latest | dot -Tsvg -o out.svg
``` ```
For more advanced use cases you can append arguments to the `docker run` For more advanced use cases you can append arguments to the `docker run`
@ -51,7 +40,7 @@ command as if you were running it in a local shell.
In most cases what you want to run are the following couple commands: In most cases what you want to run are the following couple commands:
```bash ```bash
git clone https://code.brothertec.eu/simono41/docker-network-graph.git git clone https://github.com/muratovas/docker-network-graph.git
cd docker-network-graph cd docker-network-graph
pipenv install pipenv install
pipenv run python docker-network-graph.py -o output.svg pipenv run python docker-network-graph.py -o output.svg

View file

@ -77,10 +77,11 @@ def get_unique_color() -> str:
i += 1 i += 1
else: else:
# Generate random color if we've already used the 12 preset ones # Generate random color if we've already used the 12 preset ones
c = "#{:06x}".format(random.randint(0, 0xFFFFFF)) c = '#'.join([f"{random.randint(0, 255):02x}" for _ in range(3)])
return c return c
def get_networks( def get_networks(
client: docker.DockerClient, verbose: bool client: docker.DockerClient, verbose: bool
) -> typing.Dict[str, Network]: ) -> typing.Dict[str, Network]:
@ -89,7 +90,7 @@ def get_networks(
for net in sorted(client.networks.list(), key=lambda k: k.name): for net in sorted(client.networks.list(), key=lambda k: k.name):
try: try:
gateway = net.attrs["IPAM"]["Config"][0]["Subnet"] gateway = net.attrs["IPAM"]["Config"][0]["Subnet"]
except (KeyError, IndexError, TypeError): except (KeyError, IndexError):
# This network doesn't seem to be used, skip it # This network doesn't seem to be used, skip it
continue continue
@ -233,13 +234,13 @@ def generate_graph(verbose: bool, file: str, url: str):
comment="Docker Network Graph", comment="Docker Network Graph",
engine="sfdp", engine="sfdp",
format=ext[1:], format=ext[1:],
graph_attr={'splines': 'true', 'rankdir': 'LR'}, graph_attr=dict(splines="true"),
) )
else: else:
g = Graph( g = Graph(
comment="Docker Network Graph", comment="Docker Network Graph",
engine="sfdp", engine="sfdp",
graph_attr={'splines': 'true', 'rankdir': 'LR'}, graph_attr=dict(splines="true"),
) )
for _, network in networks.items(): for _, network in networks.items():
@ -285,4 +286,4 @@ if __name__ == "__main__":
parser.add_argument("-u", "--url", help="generate link for GraphvizOnline", action="store_true") parser.add_argument("-u", "--url", help="generate link for GraphvizOnline", action="store_true")
args = parser.parse_args() args = parser.parse_args()
generate_graph(args.verbose, args.out, args.url) generate_graph(args.verbose, args.out, args.url)