Compare commits

...

2 commits

Author SHA1 Message Date
c0035c2b89 change README 2024-03-19 21:14:09 +01:00
9b0c4efe56 fix get random color 2024-03-19 20:57:48 +01:00
2 changed files with 19 additions and 9 deletions

View file

@ -3,7 +3,7 @@
Visualize the relationship between Docker networks and containers
as a neat graphviz graph.
This repository fork [e-dant/docker-network-graph](https://github.com/e-dant/docker-network-graph)
This repository fork [MuratovAS/docker-network-graph](https://github.com/MuratovAS/docker-network-graph)
Changes:
- Improved design
- Added the ability to generate url
@ -30,7 +30,18 @@ If you want to generate a graph for a remote system you can also easily
run this script inside a pre-built docker container:
```bash
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/muratovas/docker-network-graph:latest -u
build container
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`
@ -40,7 +51,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:
```bash
git clone https://github.com/muratovas/docker-network-graph.git
git clone https://code.brothertec.eu/simono41/docker-network-graph.git
cd docker-network-graph
pipenv install
pipenv run python docker-network-graph.py -o output.svg

View file

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