Introduction

Recently, I wanted to draw a simple network diagram, and I recalled a nice application I know. It can be used to draw cloud diagrams, and it supports main Cloud providers like Azure, AWS, and GCP. Just take a look at the webpage where you can find some nice examples.

I’ve prepared a simple Docker image, so you can try the application without installing anything.

Usage

The Diagrams webpage is full of nice examples and documentation, so go there for further reading. If you know Python 🐍, you are good to go 😄 Let’s see the sample provided by the developer:

# diag.py
from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

with Diagram("Web Service", show=False):
    ELB("lb") >> EC2("web") >> RDS("userdb")

Start by importing the Diagram class, EC2, RDS, and ELB. We can add a diagram’s title with Diagram("Web Service", show=False). The show=False parameter disables the auto-opening of new images (I am using Docker anyway). Another nice parameter is outformat, which can be used to specify the output file format (PNG (default), JPG, SVG, PDF, and DOT).

Docker

This is simple Dockerfile I used to build image:

FROM alpine:3.17.3

RUN mkdir /src
WORKDIR /src
# Install dependencies
RUN apk add py3-pip gcc python3-dev musl-dev graphviz fontconfig \
    # Install fonts
    && apk add font-inconsolata font-dejavu font-noto font-noto-cjk font-awesome font-noto-extra \
    && pip install diagrams

CMD [ "diagram.py" ]
ENTRYPOINT [ "python" ]

I am using Alpine Linux and set “/src” as a WORKDIR. Next, I am installing the dependencies and fonts required by Diagrams.

ENTRYPOINT [ "python" ] - python interpreter is set as the default application running after Docker image starts. CMD [ "diagram.py" ] - argument for ENTRYPOINT - the default name of the file with diagram code.

Now, we can build the image using the well-known command:

docker build . -t diagrams

Usage

To create your diagram using Docker image, run the command within the directory with the diagram code. We will mount the current directory into Docker:

docker run --rm -v ${PWD}:/src diagrams diag.py

💥💥💥 The image will be in the same directory.

Happy diagramming 😄