Skip to content
Snippets Groups Projects
David Beniamine's avatar
David Beniamine authored
bed327c4
History

A docker image to visualize docker-compose configs with mermaid.

Base on docker-compose-viz-mermaid and mermaid-cli

Examples

# Directly generate an image of with 1000px
docker run --rm -it -v $PWD:/data dbeniamine/docker-compose-viz-mermaid -M -otest.png -M -w1000
# Generate a svg with default parameters for mermaid and showing the ports
docker run --rm -it -v $PWD:/data dbeniamine/docker-compose-viz-mermaid -v -p -m
# Generates the markdown sources with a mermaid block showing ports
docker run --rm -it -v $PWD:/data dbeniamine/docker-compose-viz-mermaid -v -p -v -fMARKDOWN

Example image

%%{init: {'theme': 'default'}}%%
flowchart TB
  VLabNbook{{$PWD}} x-. /var/www/labnbook .-x front
  Vlabnbookdb([labnbook_db]) x-. /etc/mysql/conf.d .-x mariadb
  VLabNbookdb{{$PWD/db}} x-. /var/lib/mysql .-x mariadb
  front --> mariadb
  labnbookmyadmin --> mariadb
  P0((8000)) -.-> front
  P1((8002)) -. 80 .-> labnbookmyadmin

  classDef volumes fill:#fdfae4,stroke:#867a22
  class VLabNbook,Vlabnbookdb,VLabNbookdb volumes
  classDef ports fill:#f8f8f8,stroke:#ccc
  class P0,P1 ports

Configuration

I recommand to use the dcviz command to call docker-compose-viz-mermaid, it parses a complex docker-compose configuration with docker-compose config before calling the visualization tool :

To add the dcviz command, add the following code to your .bashrc, note that you can change the default arguments to suit your needs

dcviz() {
    docker-compose config > $$.yml
    docker run --rm -it -v $PWD:/data dbeniamine/docker-compose-viz-mermaid -v --ports -v $$.yml $@
    rm $$.yml > /dev/null 2>&1
}

Then you can simply run dcviz -M -omyimage.png to generate the image or dcviz -v -fMARKDOWN to get the markdown sources