2018-10-02 03:50:05 +02:00
# dive
2023-07-07 04:01:46 +02:00
[![GitHub release ](https://img.shields.io/github/release/wagoodman/dive.svg )](https://github.com/wagoodman/dive/releases/latest)
[![Validations ](https://github.com/wagoodman/dive/actions/workflows/validations.yaml/badge.svg )](https://github.com/wagoodman/dive/actions/workflows/validations.yaml)
2018-10-17 05:38:39 +02:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/wagoodman/dive )](https://goreportcard.com/report/github.com/wagoodman/dive)
2023-07-07 04:01:46 +02:00
[![License: MIT ](https://img.shields.io/badge/License-MIT%202.0-blue.svg )](https://github.com/wagoodman/dive/blob/main/LICENSE)
2019-11-13 04:54:22 +01:00
[![Donate ](https://img.shields.io/badge/Donate-PayPal-green.svg?style=flat )](https://www.paypal.me/wagoodman)
2018-10-02 03:50:05 +02:00
2019-10-08 16:47:52 +02:00
**A tool for exploring a docker image, layer contents, and discovering ways to shrink the size of your Docker/OCI image.**
2018-10-21 20:50:00 +02:00
2021-06-24 19:20:39 +02:00
2018-10-21 20:50:00 +02:00
![Image ](.data/demo.gif )
2018-10-17 04:38:41 +02:00
2018-10-17 05:27:07 +02:00
To analyze a Docker image simply run dive with an image tag/id/digest:
```bash
dive < your-image-tag >
```
2021-03-20 11:34:10 +01:00
or you can dive with docker command directly
```
alias dive="docker run -ti --rm -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive"
dive < your-image-tag >
# for example
dive nginx:latest
```
2018-10-17 05:27:07 +02:00
or if you want to build your image then jump straight into analyzing it:
```bash
dive build -t < some-tag > .
```
2019-10-08 16:47:52 +02:00
Building on Macbook (supporting only the Docker container engine)
2019-02-11 16:14:25 +01:00
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(pwd)":"$(pwd)" \
-w "$(pwd)" \
-v "$HOME/.dive.yaml":"$HOME/.dive.yaml" \
wagoodman/dive:latest build -t < some-tag > .
```
2018-12-30 20:07:56 +01:00
Additionally you can run this in your CI pipeline to ensure you're keeping wasted space to a minimum (this skips the UI):
```
CI=true dive < your-image >
```
![Image ](.data/demo-ci.png )
2018-10-17 05:27:07 +02:00
**This is beta quality!** *Feel free to submit an issue if you want a new feature or find a bug :)*
## Basic Features
**Show Docker image contents broken down by layer**
2019-10-08 15:38:41 +02:00
As you select a layer on the left, you are shown the contents of that layer combined with all previous layers on the right. Also, you can fully explore the file tree with the arrow keys.
2018-10-17 05:27:07 +02:00
2018-10-25 02:50:20 +02:00
**Indicate what's changed in each layer**
2018-10-17 05:27:07 +02:00
2019-10-08 15:38:41 +02:00
Files that have changed, been modified, added, or removed are indicated in the file tree. This can be adjusted to show changes for a specific layer, or aggregated changes up to this layer.
2018-10-17 04:38:41 +02:00
2018-10-17 05:27:07 +02:00
**Estimate "image efficiency"**
2018-10-17 04:38:41 +02:00
2019-10-08 15:38:41 +02:00
The lower left pane shows basic layer info and an experimental metric that will guess how much wasted space your image contains. This might be from duplicating files across layers, moving files across layers, or not fully removing files. Both a percentage "score" and total wasted file space is provided.
2018-10-17 04:56:35 +02:00
2018-10-17 05:27:07 +02:00
**Quick build/analysis cycles**
2018-10-25 02:50:20 +02:00
You can build a Docker image and do an immediate analysis with one command:
`dive build -t some-tag .`
2018-10-17 05:27:07 +02:00
2018-10-26 18:24:59 +02:00
You only need to replace your `docker build` command with the same `dive build`
2018-10-25 02:50:20 +02:00
command.
2018-10-17 05:27:07 +02:00
2018-12-30 20:07:56 +01:00
**CI Integration**
2019-11-05 06:05:39 +01:00
2020-09-14 11:04:57 +02:00
Analyze an image and get a pass/fail result based on the image efficiency and wasted space. Simply set `CI=true` in the environment when invoking any valid dive command.
2018-12-30 20:07:56 +01:00
2019-11-05 06:05:39 +01:00
**Multiple Image Sources and Container Engines Supported**
2019-10-09 00:55:03 +02:00
With the `--source` option, you can select where to fetch the container image from:
2019-10-08 16:47:52 +02:00
```bash
2019-10-09 01:29:04 +02:00
dive < your-image > --source < source >
```
or
```bash
dive < source > ://< your-image >
2019-10-08 16:47:52 +02:00
```
2018-10-17 05:27:07 +02:00
2019-10-09 00:55:03 +02:00
With valid `source` options as such:
- `docker` : Docker engine (the default option)
- `docker-archive` : A Docker Tar Archive from disk
- `podman` : Podman engine (linux only)
2018-10-17 05:27:07 +02:00
## Installation
**Ubuntu/Debian**
2024-02-02 15:26:06 +01:00
Using debs:
2018-10-17 05:27:07 +02:00
```bash
2024-02-02 15:26:54 +01:00
DIVE_VERSION=$(curl -sL "https://api.github.com/repos/wagoodman/dive/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
2022-05-31 10:28:52 +02:00
curl -OL https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.deb
sudo apt install ./dive_${DIVE_VERSION}_linux_amd64.deb
2018-05-13 20:54:17 +02:00
```
2018-10-17 05:27:07 +02:00
2024-02-02 15:26:06 +01:00
Using snap:
```bash
sudo snap install docker
sudo snap install dive
sudo snap connect dive:docker-executables docker:docker-executables
sudo snap connect dive:docker-daemon docker:docker-daemon
```
2018-10-17 05:27:07 +02:00
**RHEL/Centos**
```bash
2024-02-02 15:26:54 +01:00
DIVE_VERSION=$(curl -sL "https://api.github.com/repos/wagoodman/dive/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
2023-07-06 17:13:58 +02:00
curl -OL https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.rpm
2023-07-07 17:54:08 +02:00
rpm -i dive_${DIVE_VERSION}_linux_amd64.rpm
2018-10-17 05:27:07 +02:00
```
2018-11-26 03:49:35 +01:00
**Arch Linux**
2023-07-06 18:10:44 +02:00
Available in the [extra repository ](https://archlinux.org/packages/extra/x86_64/dive/ ) and can be installed via [pacman ](https://wiki.archlinux.org/title/Pacman ):
2018-11-26 03:49:35 +01:00
```bash
2023-01-29 20:15:08 +01:00
pacman -S dive
2018-11-26 03:49:35 +01:00
```
2018-10-17 05:27:07 +02:00
**Mac**
2019-07-26 21:30:44 +02:00
2021-02-26 14:58:57 +01:00
If you use [Homebrew ](https://brew.sh ):
2018-10-17 05:27:07 +02:00
```bash
brew install dive
```
2019-07-26 21:30:44 +02:00
2021-02-26 14:58:57 +01:00
If you use [MacPorts ](https://www.macports.org ):
```bash
sudo port install dive
```
2023-07-06 17:13:58 +02:00
Or download the latest Darwin build from the [releases page ](https://github.com/wagoodman/dive/releases/latest ).
2018-10-17 05:27:07 +02:00
2018-12-02 04:36:10 +01:00
**Windows**
2018-12-02 04:39:25 +01:00
2023-07-06 17:13:58 +02:00
Download the [latest release ](https://github.com/wagoodman/dive/releases/latest ).
2018-12-02 04:36:10 +01:00
2018-10-17 05:27:07 +02:00
**Go tools**
2020-03-23 09:30:22 +01:00
Requires Go version 1.10 or higher.
2019-01-21 03:13:06 +01:00
2018-10-17 05:27:07 +02:00
```bash
go get github.com/wagoodman/dive
2018-05-25 03:22:52 +02:00
```
2018-12-02 04:44:27 +01:00
*Note*: installing in this way you will not see a proper version when running `dive -v` .
2018-05-25 03:22:52 +02:00
2021-04-01 13:10:43 +02:00
**Nix/NixOS**
On NixOS:
```bash
nix-env -iA nixos.dive
```
On non-NixOS (Linux, Mac)
```bash
nix-env -iA nixpkgs.dive
```
2018-10-25 03:48:21 +02:00
**Docker**
```bash
docker pull wagoodman/dive
```
2019-07-26 21:30:44 +02:00
or
2018-10-25 03:48:21 +02:00
```bash
docker pull quay.io/wagoodman/dive
```
2019-11-05 06:05:39 +01:00
When running you'll need to include the docker socket file:
2018-10-25 03:48:21 +02:00
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
2018-10-25 03:51:34 +02:00
wagoodman/dive:latest < dive arguments . . . >
2018-10-25 03:48:21 +02:00
```
2018-11-19 17:52:10 +01:00
Docker for Windows (showing PowerShell compatible line breaks; collapse to a single line for Command Prompt compatibility)
2018-10-27 16:21:54 +02:00
```bash
2018-11-19 17:52:10 +01:00
docker run --rm -it `
-v /var/run/docker.sock:/var/run/docker.sock `
2018-11-25 02:48:31 +01:00
wagoodman/dive:latest < dive arguments . . . >
```
**Note:** depending on the version of docker you are running locally you may need to specify the docker API version as an environment variable:
```bash
DOCKER_API_VERSION=1.37 dive ...
2019-07-26 21:30:44 +02:00
```
2018-11-25 02:48:31 +01:00
or if you are running with a docker image:
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
2019-06-10 20:04:51 +02:00
-e DOCKER_API_VERSION=1.37 \
2018-11-19 17:52:10 +01:00
wagoodman/dive:latest < dive arguments . . . >
2018-10-27 16:21:54 +02:00
```
2018-12-30 20:07:56 +01:00
## CI Integration
When running dive with the environment variable `CI=true` then the dive UI will be bypassed and will instead analyze your docker image, giving it a pass/fail indication via return code. Currently there are three metrics supported via a `.dive-ci` file that you can put at the root of your repo:
```
rules:
# If the efficiency is measured below X%, mark as failed.
2019-07-27 19:15:16 +02:00
# Expressed as a ratio between 0-1.
2018-12-30 20:07:56 +01:00
lowestEfficiency: 0.95
# If the amount of wasted space is at least X or larger than X, mark as failed.
# Expressed in B, KB, MB, and GB.
highestWastedBytes: 20MB
# If the amount of wasted space makes up for X% or more of the image, mark as failed.
# Note: the base image layer is NOT included in the total image size.
2019-07-27 19:15:16 +02:00
# Expressed as a ratio between 0-1; fails if the threshold is met or crossed.
2018-12-30 20:07:56 +01:00
highestUserWastedPercent: 0.20
```
You can override the CI config path with the `--ci-config` option.
2018-11-01 04:49:31 +01:00
## KeyBindings
Key Binding | Description
-------------------------------------------|---------------------------------------------------------
2021-10-11 08:30:10 +02:00
< kbd > Ctrl + C< / kbd > or < kbd > Q< / kbd > | Exit
2019-02-18 22:59:32 +01:00
< kbd > Tab< / kbd > | Switch between the layer and filetree views
2018-11-01 04:49:31 +01:00
< kbd > Ctrl + F< / kbd > | Filter files
2019-02-18 22:59:32 +01:00
< kbd > PageUp< / kbd > | Scroll up a page
< kbd > PageDown< / kbd > | Scroll down a page
2018-11-01 04:49:31 +01:00
< kbd > Ctrl + A< / kbd > | Layer view: see aggregated image modifications
< kbd > Ctrl + L< / kbd > | Layer view: see current layer modifications
< kbd > Space< / kbd > | Filetree view: collapse/uncollapse a directory
2019-02-18 22:59:32 +01:00
< kbd > Ctrl + Space< / kbd > | Filetree view: collapse/uncollapse all directories
2018-11-01 04:49:31 +01:00
< kbd > Ctrl + A< / kbd > | Filetree view: show/hide added files
< kbd > Ctrl + R< / kbd > | Filetree view: show/hide removed files
< kbd > Ctrl + M< / kbd > | Filetree view: show/hide modified files
< kbd > Ctrl + U< / kbd > | Filetree view: show/hide unmodified files
2019-02-22 17:49:53 +01:00
< kbd > Ctrl + B< / kbd > | Filetree view: show/hide file attributes
2018-11-01 04:49:31 +01:00
< kbd > PageUp< / kbd > | Filetree view: scroll up a page
< kbd > PageDown< / kbd > | Filetree view: scroll down a page
2018-12-30 20:07:56 +01:00
## UI Configuration
2018-11-01 04:49:31 +01:00
2018-11-05 23:53:15 +01:00
No configuration is necessary, however, you can create a config file and override values:
2018-11-01 04:49:31 +01:00
```yaml
2019-10-08 16:47:52 +02:00
# supported options are "docker" and "podman"
container-engine: docker
2020-02-10 04:30:21 +01:00
# continue with analysis even if there are errors parsing the image archive
ignore-errors: false
2018-11-01 04:49:31 +01:00
log:
enabled: true
path: ./dive.log
level: info
2018-11-06 04:37:25 +01:00
# Note: you can specify multiple bindings by separating values with a comma.
# Note: UI hinting is derived from the first binding
2018-11-01 04:49:31 +01:00
keybinding:
2018-11-06 04:37:25 +01:00
# Global bindings
2018-11-01 04:49:31 +01:00
quit: ctrl+c
2019-02-22 17:49:53 +01:00
toggle-view: tab
2018-11-01 04:49:31 +01:00
filter-files: ctrl+f, ctrl+slash
2018-11-01 04:53:02 +01:00
2019-07-26 21:30:44 +02:00
# Layer view specific bindings
2018-11-01 04:49:31 +01:00
compare-all: ctrl+a
compare-layer: ctrl+l
2018-11-01 04:53:02 +01:00
2018-11-06 04:37:25 +01:00
# File view specific bindings
2018-11-01 04:49:31 +01:00
toggle-collapse-dir: space
2019-02-22 17:49:53 +01:00
toggle-collapse-all-dir: ctrl+space
2018-11-01 04:49:31 +01:00
toggle-added-files: ctrl+a
toggle-removed-files: ctrl+r
toggle-modified-files: ctrl+m
toggle-unmodified-files: ctrl+u
2019-02-22 17:49:53 +01:00
toggle-filetree-attributes: ctrl+b
2018-11-01 04:49:31 +01:00
page-up: pgup
page-down: pgdn
2019-07-26 21:30:44 +02:00
2018-11-06 04:37:25 +01:00
diff:
2020-09-14 11:04:57 +02:00
# You can change the default files shown in the filetree (right pane). All diff types are shown by default.
2018-11-06 04:37:25 +01:00
hide:
- added
- removed
2019-11-22 20:35:03 +01:00
- modified
- unmodified
2018-11-06 04:37:25 +01:00
2018-11-24 03:53:08 +01:00
filetree:
# The default directory-collapse state
collapse-dir: false
2018-11-25 02:21:36 +01:00
# The percentage of screen width the filetree should take on the screen (must be >0 and < 1 )
pane-width: 0.5
2019-07-26 21:30:44 +02:00
2019-02-22 17:49:53 +01:00
# Show the file attributes next to the filetree
show-attributes: true
2018-11-25 02:21:36 +01:00
2018-11-06 04:37:25 +01:00
layer:
2020-09-14 11:04:57 +02:00
# Enable showing all changes from this layer and every previous layer
2018-11-06 04:37:25 +01:00
show-aggregated-changes: false
2018-11-01 04:49:31 +01:00
```
2018-11-05 23:53:15 +01:00
dive will search for configs in the following locations:
2019-02-04 04:11:32 +01:00
- `$XDG_CONFIG_HOME/dive/*.yaml`
- `$XDG_CONFIG_DIRS/dive/*.yaml`
- `~/.config/dive/*.yaml`
2018-11-05 23:53:15 +01:00
- `~/.dive.yaml`
2022-05-14 08:33:31 +02:00
`.yml` can be used instead of `.yaml` if desired.