Giter VIP home page Giter VIP logo

docker-compose-viz's Introduction

docker-compose-viz

Average time to resolve an issue Percentage of issues still open Docker Stars Docker Pulls

How to use

Docker

Considering the current working directory is where your docker-compose.yml file is located:

docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml
# PowerShell
docker run --rm -it --name dcv -v ${pwd}:/input pmsipilot/docker-compose-viz render -m image docker-compose.yml

This will generate the docker-compose.png file in the current working directory.

PHP

Before you start, make sure you have:

  • Composer installed,
  • PHP 7.2 (at least) installed,
  • GraphViz installed (see below for a guide on how to install it)

Self-Compiled

git clone https://github.com/pmsipilot/docker-compose-viz.git

make vendor

Via Composer

composer install --prefer-dist

bin/dcv

Install GraphViz

  • On MacOS:

    brew install graphviz
  • On Debian:

    sudo apt-get install graphviz

Usage

Usage:
  render [options] [--] [<input-file>]

Arguments:
  input-file                         Path to a docker compose file [default: "./docker-compose.yml"]

Options:
      --override=OVERRIDE            Tag of the override file to use [default: "override"]
  -o, --output-file=OUTPUT-FILE      Path to a output file (Only for "dot" and "image" output format) [default: "./docker-compose.dot" or "./docker-compose.png"]
  -m, --output-format=OUTPUT-FORMAT  Output format (one of: "dot", "image", "display") [default: "display"]
      --only=ONLY                    Display a graph only for a given services (multiple values allowed)
  -f, --force                        Overwrites output file if it already exists
      --no-volumes                   Do not display volumes
  -r, --horizontal                   Display a horizontal graph
      --ignore-override              Ignore override file

How to read the graph

Links

Links (from services.<service>.links) are displayed as plain arrows pointing to the service that declares the link:

links

If we look at the link between mysql and ambassador, it reads as follow: "mysql is known as mysql in ambassador." If we look at the link between ambassador and logs, it reads as follow: "ambassador is known as logstash in logs."

External links are displayed using the same shapes but are grayed:

external_links

Volumes

Volumes (from services.<service>.volumes_from) are displayed as dashed arrows pointing to the service that uses the volumes:

volumes

If we look at the link between logs and api, it reads as follow: "api uses volumes from logs."

Volumes (from services.<service>.volumes) are displayed as folders with the host directory as label and are linked to the service that uses them dashed arrows.

If we look at the link between ./api and api, it reads as follow: "the host directory ./apiis mounted as a read-write folder on /src in api." Bidirectional arrows mean the directory is writable from the container.

If we look at the link between ./etc/api/php-fpm.d and api, it reads as follow: "the host directory ./etc/api/php-fpm.dis mounted as a read-only folder on /usr/local/etc/php-fpm.d in api." Unidirectional arrows mean the directory is not writable from the container.

Dependencies

Dependencies (from services.<service>.depends_on) are displayed as dotted arrows pointing to the service that declares the dependencies:

dependencies

If we look at the link between mysql and logs, it reads as follow: "mysql depends on logs."

Ports

Ports (from services.<service>.ports) are displayed as circle and are linked to containers using plain arrows pointing to the service that declares the ports:

ports

If we look at the link between port 2480 and orientdb, it reads as follow: "traffic coming to host port 2480 will be routed to port 2480 of orientdb." If we look at the link between port 2580 and elk, it reads as follow: "traffix coming to host port 2580 will be routed to port 80 of elk."

Extends

Extended services (from services.<service>.extends) are displayed as components (just like normal services). The links between them and the extending services are displayed as inverted arrows:

extends

If we look at the link between mysql and db, it reads as follow: "mysql extends service db".

Networks

Networks (from networks.<network>) are displayed as pentagons. The links between them and services are displayed as plain arrows pointing to the network:

networks

If we look at the link between mysql and the global network, it reads as follow: "mysql is known as mysql, db and reldb in the global network.

The legacy network is an external so it's displayed as a grayed pentagon.

Examples

dot renderer

digraph G {
  graph [pad=0.5]
  "front" [shape="component"]
  "http" [shape="component"]
  2380 [shape="circle"]
  "ambassador" [shape="component"]
  "mysql" [shape="component"]
  "orientdb" [shape="component"]
  "elk" [shape="component"]
  "api" [shape="component"]
  "piwik" [shape="component"]
  "logs" [shape="component"]
  "html" [shape="component"]
  2580 [shape="circle"]
  2480 [shape="circle"]
  "http" -> "front" [style="solid"]
  2380 -> "front" [style="solid" label=80]
  "mysql" -> "ambassador" [style="solid"]
  "orientdb" -> "ambassador" [style="solid"]
  "elk" -> "ambassador" [style="solid"]
  "api" -> "http" [style="solid"]
  "piwik" -> "http" [style="solid"]
  "logs" -> "http" [style="dashed"]
  "piwik" -> "http" [style="dashed"]
  "html" -> "http" [style="dashed"]
  "ambassador" -> "api" [style="solid" label="graphdb"]
  "ambassador" -> "api" [style="solid" label="reldb"]
  "logs" -> "api" [style="dashed"]
  "ambassador" -> "logs" [style="solid" label="logstash"]
  2580 -> "elk" [style="solid" label=80]
  "ambassador" -> "piwik" [style="solid" label="db"]
  2480 -> "orientdb" [style="solid"]
}

image renderer

image renderer

display renderer

display renderer

Troubleshooting

Getting "failed to open stream: Permission denied"?

Make sure the target directory is writeable by the user in the Docker container. Or create a writeable directory first. See workaround #41

License

The MIT License (MIT) Copyright ยฎ 2020 PMSIpilot

docker-compose-viz's People

Contributors

artospaj avatar edwardtheharris avatar gplanchat avatar jubianchi avatar k----n avatar karlwilbur avatar markiewb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-compose-viz's Issues

How to use it on docker ?

Hi,
I don't understand how to use it with the Docker command. Could you explain it a little bit more ?

failed to open stream: Permission denied

I got the latest Docker image from Docker Hub:

> docker run --rm -it --name dcv -v $(pwd):/input:rw pmsipilot/docker-compose-viz
Warning: file_put_contents(/input/docker-compose.png): failed to open stream: Permission denied in /dcv/src/application.php on line 137

I copied the docker-compose.yml to /tmp did chmod a+r on it, and ran the docker run command there. It worked fine.

This is due to specifying the dcv username in Dockerfile. It is easy to fix by not imposing a username and having the root user being used.

This issue was mentioned before in #21, but as part of a separate thread.

Volume long syntax referes to a single node 'named:'

When using the long syntax for volumes, there is only one volume node generated with the label 'named:' (see screenshot), that is connected to every service using a volume with long syntax.

volumes:
  - type: bind
    source: /data/some_directory
    target: /some_directory

image

Failure on override

Suppose you have docker-compose.yml

version: '3'
services:
  web:
    image: 'nginx'
    ports:
    - 80
    links:
    - db
  db:
    image: mysql

and docker-compose.override.yml:

version: '3'
services:
  sonarqube:
    image: 'sonarqube'
    links:
    - db

the output is:

image

File are correct since docker-compose config output is

services:
  db:
    image: mysql
  sonarqube:
    image: sonarqube
    links:
    - db
  web:
    image: nginx
    links:
    - db
    ports:
    - 80/tcp
version: '3.0'

BTW if you copy docker-compose config's output in a new 'docker-compose.yml` the image is rendered correctly

image

`--output-format=display` has no effect (linux)

I'm using ubuntu.
The output to display option has no effect.

My default image viewer is eog (gnome image viewer)

$ uname -a
Linux lrkwz-Precision-SSD-M4500 4.13.0-26-generic #29~16.04.2-Ubuntu SMP Tue Jan 9 22:00:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.3 LTS
Release:	16.04
Codename:	xenial
$ gnome-shell --version
GNOME Shell 3.18.5
$ eog --version
GNOME Image Viewer 3.18.2

Render SVGs?

Hey there, I was wondering if this project can also render SVGs?

The reason is that I want to add it as a CI entry that auto-commits the repository structure on regular basis, but that means committing multiple kilobytes of blob if I were to generate PNGs all the time, whereas an SVG image is much more efficient.

If the tool uses dot (graphviz) internally, -Tsvg should suffice, and I can try sending a patch if pointed at the right place and this is a welcome addition.

Or should I use dot as format, and then render the image myself?

Doesn't source related .env file?

It appears that this nice utility does not pre-process the docker-compose.yml file with its .env file, if a .env file is used to parameterize the compose file. The result is that variable replacements are blanked in the generated image.

Is there an argument or step to use to get the visualizer to use environment variable substitutions before parsing the text of the compose specification?

/dcv/bin/entry_script.sh: line 12: Warning:: not found

I ran the command docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml in the directory that contained the docker project along with docker-compose.yml. But got this error.

/dcv/bin/entry_script.sh: line 12: Warning:: not found

I have installed PHP7.1 and composer locally, is there any configuration that I need to make to get this working?

Docker - failed to open stream permission denied

I tried docker-compose-viz

$ docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml
Warning: file_put_contents(/input/docker-compose.png): failed to open stream: Permission denied in /dcv/src/application.php on line 138
Linux myserver 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1

Option to exclude ports

In order to clean up the resulting diagram, as for --no-volumes it would be nice having the ability to selectively exclude features such as:

--no-ports
--no-port-routes
--no-dependencies
--no-extends
--no-networks

Verbosity

The options -v, -vv and -vvv have no effect.

file_put_contents Permission denied

I followed the instructions in the readme to install docker-compose-viz, but while running

docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml

I get the error:

Warning: file_put_contents(/input/docker-compose.png): failed to open stream: Permission denied in /dcv/src/application.php on line 137

What could be the problem?

๐Ÿ˜Ž Dark Mode Please ๐Ÿ˜Ž

It would be awesome to be able to pass -dark to render an inverted image, also would be great to be able to define some other customizations as line/text color and even background opacity.
Just pitching, it's already great and inverting the image externally works great.

YAML anchor throws error

As @Xenira stated in #33 , the project has an issue if compose extension fields are used.
invalid example:

x-environment:
  &default-tz-puid-pgid
  TZ: $TZ
  PUID: $PUID
  PGID: $PGID

services:
  service1:
    environment:
      <<: *default-tz-puid-pgid
      Key0: Value0
...

valid example

x-environment:
  &default-tz-puid-pgid
  TZ: $TZ
  PUID: $PUID
  PGID: $PGID

services:
  service1:
    environment:
      <<: &default-tz-puid-pgid
      Key0: Value0
...

The error thrown would be:

In functions.php line 41:

  File "docker-compose.yml" does not contain valid YAML


In Parser.php line 476:

  Unable to parse at line 21 (near "<< * default-tz-puid-pgid").

To me it looks like the filter/search value for the yaml merge is not perfect.
If you change <<: *networking-reference to << : &networking-reference no error is thrown but its not a valid yaml/compose-file anymore.
So the script is happy with defining a yaml anchor (&) but not using it (*)
Further information on using yaml anchor in compose

Seems to be a Symfony error. So it seems we have to wait till docker-compose or symfony adjust.

Read override files.

Would be nice if the parsing of the yml took into account the override.yml as well.

App (both Docker and native flavour) doesn't work, PHP error

When executing your command as stated in the README I get this error:

Fatal error: Uncaught TypeError: Argument 2 passed to PMSIpilot\DockerComposeViz\addService() must be of the type string, array given, called in /dcv/src/functions.php on line 262 and defined in /dcv/src/functions.php:338
Stack trace:
#0 /dcv/src/functions.php(262): PMSIpilot\DockerComposeViz\addService(Object(Fhaculty\Graph\Graph), Array)
#1 /dcv/src/functions.php(92): PMSIpilot\DockerComposeViz\makeVerticesAndEdges(Object(Fhaculty\Graph\Graph), Array, Array, Array, true, 'docker-compose....')
#2 /dcv/src/application.php(81): PMSIpilot\DockerComposeViz\createGraph(Array, Array, Array, true, 'docker-compose....')
#3 [internal function]: Closure->PMSIpilot\DockerComposeViz\{closure}(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /dcv/vendor/symfony/console/Command/Command.php(262): call_user_func(Object(Closure), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /dcv/vendor/symfony/console/Application. in /dcv/src/functions.php on line 338

Nice ! Thanks !

Very nice tool allowing us to quickly visualize the architecture implemented by Docker, services and interdependencies as well as exposed ports, volumes, networks, ...

Thanks for your work.

Read multiple yml files

Or, as alternative, read .env and search COMPOSE_FILE var to read all yml configs for projects.

We divide all infrastructure of project to separated services. So, we have .env, where we write all ymls that are needed to start the project.
For example: COMPOSE_FILE=docker-compose.yaml:docker-compose.legacy.yaml:docker-compose.env.yaml

Here it in docker-compose refs: https://docs.docker.com/compose/reference/envvars/#compose_file

More detail on invalid YAML

Expected behavior: When provided with invalid yaml file, point to line (and when possible column) of malformed yaml

Current behavior: 'File "%s" does not contain valid YAML' is thrown as a new InvalidArgumentException. (functions.php line 46)

The file I used passed a different yaml validator and works with compose (compose file version 3.2) but fails with this tool. Maybe a more detailed error message can help to resolve the problem.

Wrong display of ports

Hey there,

if docker-compose looks like this:

ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"

Then the created image shows 0 as port instead of 80.

Could not execute /dcv/bin/dcv

docker: Error response from daemon: oci runtime error: exec: "/dcv/bin/dcv": permission denied.

There should be a chmod +x in the Dockerfile

Using "Long Syntax" for volumes generates `PHP Warning: explode() expects parameter 2 to be string, array given`

Running from the CLI, I get:

-> % ~/packages/docker-compose-viz/bin/dcv render
PHP Warning:  explode() expects parameter 2 to be string, array given in /home/karl/packages/docker-compose-viz/src/functions.php on line 504
PHP Notice:  Undefined offset: 0 in /home/karl/packages/docker-compose-viz/src/functions.php on line 513
PHP Notice:  Undefined offset: 0 in /home/karl/packages/docker-compose-viz/src/functions.php on line 513
PHP Warning:  explode() expects parameter 2 to be string, array given in /home/karl/packages/docker-compose-viz/src/functions.php on line 504
PHP Notice:  Undefined offset: 0 in /home/karl/packages/docker-compose-viz/src/functions.php on line 513
PHP Notice:  Undefined offset: 0 in /home/karl/packages/docker-compose-viz/src/functions.php on line 513

Running from the Docker image also gives similar warnings:

-> % docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml

Warning: explode() expects parameter 2 to be string, array given in /dcv/src/functions.php on line 504

Warning: explode() expects parameter 2 to be string, array given in /dcv/src/functions.php on line 504

In my docker-compose.yml I am using the long syntax; I have the following:

    volumes:
      - type: bind
        source: ./app-source
        target: /place/to/bin/app-source
      - type: bind
        source: ./logs
        target: /place/to/bin/logs

...which is what seems to be causing the trouble when read in by this line:

list($host, $container, $attr) = explodeMapping($volume);

It seems that this only supports the short syntax.

I am going to see if I can put together a fix for this and submit a PR.

requires php ^7.1.3

The README says the PHP requirement is 'PHP 7' but trying to install from the included composer.lock file, I get a bunch of "problems" due to PHP version. E.G.:

  Problem 1
    - Installation request for symfony/debug v4.0.3 -> satisfiable by symfony/debug[v4.0.3].
    - symfony/debug v4.0.3 requires php ^7.1.3 -> your PHP version (7.0.28) does not satisfy that requirement.

This was handled for me by deleting the lock file file and reinstalling.

rm composer.lock
composer install --prefer-dist

I am running Ubuntu 16.04.4 (PHP 7.0.28-0ubuntu0.16.04.1).

Include multiple docker-compose.yml in chart

A really nice tool - I like it a lot.

I'm not sure if it is hard to do but I could use if it would include multiple docker-compose files. I have a complex setup where i use docker-compose-letsencrypt-nginx-proxy-companion so I have a shared network between several dockers. Would be nice to do a system-wide drawing :)

Malformed inline YAML string error when using command arguments list

Thanks, this package saved me a lot of time.

I get an error when using docker-compose commands in list format, e.g.

version: "3.9" 

services:
  example:
    command: 
        [
            "bundle", 
            "exec", 
            "thin", 
            "-p", 
            "3000"
        ]

producing a Malformed inline YAML string error. Would it be possible to add support for this? In the meantime I can work around it by commenting out the command, creating the graph, and then reverting my changes.

Volume arrow destination label is not consistent

Issue

In case of

        volumes:
            - abc:/xyz

The arrow between volume abc and destination /xyz is labeled just by xyz.
The forward slash is included once the destination path has more than 2 levels.

Solution

I think the root "/" should be included - it can help to distinguish labels when graph gets complicated. But feel free to close if you don't agree ;)

TO-VERIFY

Also, I am getting weird behaviour - if the destination directory has two levels (e.g. "abc:/xyz/klm"), the second folder is not shown at all (label is only "xyz")

Image height is not adjusted when overwriting existing image

Expected behavior: When using the force flag a new image (with new dimensions) is created and overwrites the current image.
Current behavior: The new image is written, but the dimensions are staying the same, causing information to be lost / out of bounds.

Steps to reproduce:

  1. Create image using docker-compose.yml
  2. Edit the docker-compose.yml
  3. Recreate the image using the force option

File /path/to/docker-compose.yml does not exist

I cd into my project folder.

$ docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image ./docker-compose.yml

In functions.php line 35:

File "./docker-compose.yml" does not exist

render [--override OVERRIDE] [-o|--output-file OUTPUT-FILE] [-m|--output-format OUTPUT-FORMAT] [--graphviz-output-format GRAPHVIZ-OUTPUT-FORMAT] [--only ONLY] [-f|--force] [--no-volumes] [--no-networks] [--no-ports] [-r|--horizontal] [--ignore-override] [--background BACKGROUND] [--] []

I can confirm docker-compose.yml exists in the current working directory.

Am i missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.