Dockerイメージ、レイヤーコンテンツを探索し、Docker/OCIイメージのサイズを縮小する方法を見つけるためのツール。
Dockerイメージを分析するには、イメージタグ/ID/ダイジェストを使用してdiveを実行するだけです。
dive <your-image-tag>
または、イメージを作成したい場合は、すぐに分析に取り掛かります。
dive build -t <some-tag> .
Macbookでのビルド(Dockerコンテナエンジンのみをサポート)
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> .
さらに、これをCIパイプラインで実行して、無駄なスペースを最小限に抑えることができます(これによりUIがスキップされます)。
CI=true dive <your-image>
これはベータ品質です! 新しい機能が必要な場合やバグを見つけた場合は、遠慮なく問題を送信してください:)
Dockerイメージのコンテンツをレイヤーごとに分類して表示
左側のレイヤーを選択すると、そのレイヤーのコンテンツが右側の前のすべてのレイヤーと組み合わされて表示されます。また、矢印キーを使用してファイルツリーを完全に探索できます。
各レイヤーで何が変更されたかを示します
変更、変更、追加、または削除されたファイルは、ファイルツリーに表示されます。これは、特定のレイヤーの変更、またはこのレイヤーまでの集約された変更を表示するように調整できます。
「画像効率」を見積もる
左下のペインには、基本的なレイヤー情報と、画像に含まれる無駄なスペースの量を推測する実験的な指標が表示されます。これは、レイヤー間でファイルを複製したり、レイヤー間でファイルを移動したり、ファイルを完全に削除しなかったりしたことが原因である可能性があります。「スコア」のパーセンテージと無駄なファイルスペースの合計の両方が提供されます。
クイックビルド/分析サイクル
Dockerイメージを構築し、次の1つのコマンドですぐに分析を行うことができます。
dive build -t some-tag .
docker buildコマンドを同じコマンドに置き換えるだけです
dive build。
CI統合
画像を分析し、画像の効率と無駄なスペースに基づいて合格/不合格の結果を取得します。
CI=true有効なダイビングコマンドを呼び出すときは、環境に設定するだけです。
サポートされている複数の画像ソースとコンテナエンジン
この
--sourceオプションを使用すると、コンテナイメージを取得する場所を選択できます。
dive <your-image> --source <source>
また
dive <source>://<your-image>
そのような有効な
sourceオプションで:
docker:Dockerエンジン(デフォルトオプション)
docker-archive:ディスクからのDockerTarアーカイブ
podman:Podmanエンジン(Linuxのみ)
Ubuntu / Debian
wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb
sudo apt install ./dive_0.9.2_linux_amd64.deb
RHEL / Centos
curl -OL https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.rpm
rpm -i dive_0.9.2_linux_amd64.rpm
Arch Linux
Arch User Repository(AUR)でダイビングとして利用できます。
yay -S dive
上記の例はyay
、AURパッケージをインストールするためのツールとして想定しています。
マック
Homebrewを使用する場合:
brew install dive
MacPortsを使用する場合:
sudo port install dive
または、リリースページから最新のDarwinビルドをダウンロードします。
ウィンドウズ
最新リリースをダウンロードします。
Goツール Goバージョン1.10以降が必要です。
go get github.com/wagoodman/dive
注:この方法でインストールすると、実行時に適切なバージョンが表示されません
dive -v。
Docker
docker pull wagoodman/dive
また
docker pull quay.io/wagoodman/dive
実行するときは、dockerソケットファイルを含める必要があります。
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
wagoodman/dive:latest <dive arguments...>
Docker for Windows(PowerShell互換の改行を表示します。コマンドプロンプトとの互換性のために1行に折りたたむ)
docker run --rm -it `
-v /var/run/docker.sock:/var/run/docker.sock `
wagoodman/dive:latest <dive arguments...>
注:ローカルで実行しているDockerのバージョンによっては、DockerAPIのバージョンを環境変数として指定する必要がある場合があります。
DOCKER_API_VERSION=1.37 dive ...
または、Dockerイメージを使用して実行している場合:
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_API_VERSION=1.37 \
wagoodman/dive:latest <dive arguments...>
環境変数を使用してダイビングを実行すると
CI=true、ダイビングUIがバイパスされ、代わりにDockerイメージが分析され、リターンコードを介して合格/不合格が示されます。現在
.dive-ci、リポジトリのルートに配置できるファイルを介してサポートされている3つのメトリックがあります。
rules: # If the efficiency is measured below X%, mark as failed. # Expressed as a ratio between 0-1. 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. # Expressed as a ratio between 0-1; fails if the threshold is met or crossed. highestUserWastedPercent: 0.20
オプションを使用して、CI構成パスをオーバーライドできます
--ci-config。
キーバインディング | 説明 |
---|---|
Ctrl + C | 出口 |
Tab | レイヤービューとファイルツリービューを切り替えます |
Ctrl + F | フィルターファイル |
PageUp | ページを上にスクロール |
PageDown | ページを下にスクロール |
Ctrl + A | レイヤービュー:集約された画像の変更を参照 |
Ctrl + L | レイヤービュー:現在のレイヤーの変更を確認 |
Space | ファイルツリービュー:ディレクトリの折りたたみ/折りたたみ解除 |
Ctrl + Space | ファイルツリービュー:すべてのディレクトリを折りたたみ/折りたたみ解除 |
Ctrl + A | ファイルツリービュー:追加されたファイルの表示/非表示 |
Ctrl + R | ファイルツリービュー:削除されたファイルの表示/非表示 |
Ctrl + M | ファイルツリービュー:変更されたファイルの表示/非表示 |
Ctrl + U | ファイルツリービュー:変更されていないファイルの表示/非表示 |
Ctrl + B | ファイルツリービュー:ファイル属性の表示/非表示 |
PageUp | ファイルツリービュー:ページを上にスクロール |
PageDown | ファイルツリービュー:ページを下にスクロール |
構成は必要ありませんが、構成ファイルを作成して値をオーバーライドできます。
# supported options are "docker" and "podman"
container-engine: docker
# continue with analysis even if there are errors parsing the image archive
ignore-errors: false
log:
enabled: true
path: ./dive.log
level: info
# Note: you can specify multiple bindings by separating values with a comma.
# Note: UI hinting is derived from the first binding
keybinding:
# Global bindings
quit: ctrl+c
toggle-view: tab
filter-files: ctrl+f, ctrl+slash
# Layer view specific bindings
compare-all: ctrl+a
compare-layer: ctrl+l
# File view specific bindings
toggle-collapse-dir: space
toggle-collapse-all-dir: ctrl+space
toggle-added-files: ctrl+a
toggle-removed-files: ctrl+r
toggle-modified-files: ctrl+m
toggle-unmodified-files: ctrl+u
toggle-filetree-attributes: ctrl+b
page-up: pgup
page-down: pgdn
diff:
# You can change the default files shown in the filetree (right pane). All diff types are shown by default.
hide:
- added
- removed
- modified
- unmodified
filetree:
# The default directory-collapse state
collapse-dir: false
# The percentage of screen width the filetree should take on the screen (must be >0 and <1)
pane-width: 0.5
# Show the file attributes next to the filetree
show-attributes: true
layer:
# Enable showing all changes from this layer and every previous layer
show-aggregated-changes: false
diveは、次の場所で構成を検索します。
$XDG_CONFIG_HOME/dive/*.yaml
$XDG_CONFIG_DIRS/dive/*.yaml
~/.config/dive/*.yaml
~/.dive.yaml