Compare commits

..

No commits in common. "main" and "v0.0.3" have entirely different histories.
main ... v0.0.3

2 changed files with 10 additions and 23 deletions

View file

@ -3,7 +3,7 @@
Visualize the relationship between Docker networks and containers
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:
- Improved design
- Added the ability to generate url
@ -29,22 +29,8 @@ Changes:
If you want to generate a graph for a remote system you can also easily
run this script inside a pre-built docker container:
build container
```bash
docker build . -t code.brothertec.eu/simono41/docker-network-graph:latest
```
and create a PNG
```bash
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
```bash
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
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/muratovas/docker-network-graph:latest -u
```
For more advanced use cases you can append arguments to the `docker run`
@ -54,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:
```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
pipenv install
pipenv run python docker-network-graph.py -o output.svg

View file

@ -23,7 +23,7 @@ COLORS = [
"#b2df8a",
"#fdbf6f",
"#cab2d6",
"#90f530",
"#ffff99",
"#0d8bad",
"#e98420",
"#0e9997",
@ -77,10 +77,11 @@ def get_unique_color() -> str:
i += 1
else:
# 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
def get_networks(
client: docker.DockerClient, verbose: bool
) -> typing.Dict[str, Network]:
@ -89,7 +90,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, TypeError):
except (KeyError, IndexError):
# This network doesn't seem to be used, skip it
continue
@ -233,13 +234,13 @@ def generate_graph(verbose: bool, file: str, url: str):
comment="Docker Network Graph",
engine="sfdp",
format=ext[1:],
graph_attr=dict(splines="true", rankdir="LR", bgcolor="transparent"),
graph_attr=dict(splines="true"),
)
else:
g = Graph(
comment="Docker Network Graph",
engine="sfdp",
graph_attr=dict(splines="true", rankdir="LR", bgcolor="transparent"),
graph_attr=dict(splines="true"),
)
for _, network in networks.items():