DEV Community

krishna
krishna

Posted on

9 3

Creating block diagrams from docker-compose files

A docker-compose file contains the definition of all the services that needs to run in harmony to successfully deploy an app stack.

When services and their interactions are defined clearly in a compose file manually charting a block diagram to list those services and their interaction is redundant, isn't it ? that was the thought I had when I needed to chart a block diagram for documenting my architecture.

A quick search using "tool to convert a docker compose file to a block diagram" yielded this awesome repo https://github.com/pmsipilot/docker-compose-viz

The code in this repo will help us to chart a block diagram from a docker compose file.

Lets create one!
  • Sample docker-compose of a simple SaaS stack

    version: '3.4'
    services:
    rabbitmq:
    image: rabbitmq:3-management
    ports:
    - "15672:15672"
    - "5672:5672"
    deploy:
    replicas: 1
    placement:
    constraints: [node.role == manager]
    microservice:
    image: nameko-microservice
    restart: always
    deploy:
    replicas: 1
    depends_on:
    - rabbitmq
    - logstash
    db:
    image: mariadb:10.3
    volumes:
    - ./mysqldb_data:/var/lib/mysql
    ports:
    - "3306:3306"
    deploy:
    replicas: 1
    placement:
    constraints: [node.role == manager]
    resources:
    reservations:
    memory: 128M
    limits:
    memory: 256M
    restapi:
    image: restapi
    restart: always
    ports:
    - "8000:8000"
    deploy:
    mode: global
    depends_on:
    - db
    - microservice
    - logstash
    nginx:
    image: ui
    restart: always
    ports:
    - "80:80"
    deploy:
    replicas: 1
    depends_on:
    - restapi
    elasticsearch:
    image: elasticsearch:2
    command: elasticsearch -Des.network.host=0.0.0.0
    ports:
    - "9200:9200"
    - "9300:9300"
    kibana:
    image: kibana:latest
    build: kibana/
    volumes:
    - ./kibana/config/:/opt/kibana/config/
    ports:
    - "5601:5601"
    depends_on:
    - elasticsearch
    logstash:
    build: logstash/
    command: logstash -f /etc/logstash/conf.d/logstash.conf
    image: logstash:latest
    volumes:
    - ./logstash/config:/etc/logstash/conf.d
    ports:
    - "5000:5000"
    depends_on:
    - elasticsearch
  • Command to execute

    docker run 
    --rm -it \
    --name dcv \ 
    -v /home/user/blog:/input pmsipilot/docker-compose-viz \
    render -m image \
    --force docker-compose.yml \
    --output-file=topology.png \
    --no-volumes \
    --no-ports \
    --no-networks
    
  • Ouptput

Alt Text

  • Command - With port numbers
docker run 
--rm -it \
--name dcv \ 
-v /home/user/blog:/input pmsipilot/docker-compose-viz \
render -m image \
--force docker-compose.yml \
--output-file=topology.png \
--no-volumes \
--no-networks
  • Ouptput - with ports
    Alt Text

  • Command - With volumes

docker run 
--rm -it \
--name dcv \ 
-v /home/user/blog:/input pmsipilot/docker-compose-viz \
render -m image \
--force docker-compose.yml \
--output-file=topology.png \
--no-ports \
--no-networks
  • Ouptput - with volumes Alt Text

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay