/dockerfilegraph

Visualize your multi-stage Dockerfiles

Primary LanguageGoMIT LicenseMIT

dockerfilegraph

GitHub Workflow Status Go Report Card GitHub release (latest SemVer) GitHub

dockerfilegraph visualizes your multi-stage Dockerfiles.

It creates a visual graph representation of the build process. The graph contains the following nodes:

  • All build stages
  • The default build target highlighted in grey
  • External base images with dashed borders

The edges of the graph represent:

  • FROM dependencies with a full arrow head
  • COPY --from=... dependencies with an empty arrow head
  • RUN --mount=type=cache,from=... dependencies with an empty diamond arrow head

You can add an optional legend to the graph and change the output format and resolution. For all the details, see the options below.

Example Output

Default

Example output


Including a Legend

Example output including a legend

Getting Started

Prerequisites

  • A multi-stage Dockerfile file in your current working directory

Installation and Usage

Running dockerfilegraph without any arguments will create a Dockerfile.pdf in your current working directory. This PDF contains a visual graph representation of your multi-stage Dockerfile.

Docker / nerdctl

Image based on Ubuntu 20.04
docker run \
  --rm \
  --workdir /workspace \
  --volume "$(pwd)":/workspace \
  ghcr.io/patrickhoefler/dockerfilegraph
Image based on Alpine Linux
docker run \
  --rm \
  --workdir /workspace \
  --volume "$(pwd)":/workspace \
  ghcr.io/patrickhoefler/dockerfilegraph:alpine
brew install patrickhoefler/tap/dockerfilegraph
dockerfilegraph

Build from Source

Make sure that Graphviz is installed locally.

Then:

go build
./dockerfilegraph

More Options

❯ dockerfilegraph --help
dockerfilegraph visualizes your multi-stage Dockerfile.
It outputs a graph representation of the build process.

Usage:
  dockerfilegraph [flags]

Flags:
  -d, --dpi int   Dots per inch of the PNG export (default 96)
  -h, --help      help for dockerfilegraph
  -l, --legend    Add a legend (default false)
  -o, --output    Output file format. One of: canon, dot, pdf, png (default pdf)

License

MIT