Compare commits
No commits in common. "c0035c2b899903696f599a7d00fc035521f3d09c" and "84387e105d4fa40d2fa84586acef5975a2102d93" have entirely different histories.
c0035c2b89
...
84387e105d
2 changed files with 9 additions and 19 deletions
17
README.md
17
README.md
|
@ -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
|
||||
|
@ -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:
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
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`
|
||||
|
@ -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:
|
||||
|
||||
```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
|
||||
|
|
|
@ -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={'splines': 'true', 'rankdir': 'LR'},
|
||||
graph_attr=dict(splines="true"),
|
||||
)
|
||||
else:
|
||||
g = Graph(
|
||||
comment="Docker Network Graph",
|
||||
engine="sfdp",
|
||||
graph_attr={'splines': 'true', 'rankdir': 'LR'},
|
||||
graph_attr=dict(splines="true"),
|
||||
)
|
||||
|
||||
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")
|
||||
args = parser.parse_args()
|
||||
|
||||
generate_graph(args.verbose, args.out, args.url)
|
||||
generate_graph(args.verbose, args.out, args.url)
|
Loading…
Reference in a new issue