このチュートリアルでは、Container-diffとは何か、さまざまなLinuxディストリビューションにContainer-diffをインストールする方法、そして最後にContainer-diffを使用してコンテナーイメージを分析および比較する方法を学習します。
はじめに
コンテナ上でアプリケーションを構築している人たちに朗報です。
このシナリオを想像してください。あなたはソフトウェア開発者です。あなたは、他の誰かによって維持されているランタイムコンテナイメージで、アプリケーションに取り組んでいます。
開発の途中で、コンテナイメージの元の作成者は、更新されたシステムパッケージを含むそのベースイメージの新しいバージョンをリリースします。
更新されたベースイメージをダウンロードし、その上でアプリケーションの再構築を続行します。突然、アプリケーションが機能しなくなりました。
前のイメージでは正常に機能しましたが、アプリケーションは最新のベースイメージでは機能しませんでした。
また、アプリケーションがベースイメージの以前のバージョンのシステムパッケージでうまく機能したこともかなり確信していますが、どれがどれかはわかりません。ここで"Container-diff" 助けになります。
Container-diffとは何ですか?
Container-diffは、 Googleのオープンソースツールです。 これは、Googleクラウドプラットフォームでホストされているコンテナイメージを分析および比較するのに役立ちます 。
Container-diffは、2つのベースイメージ間で行われた変更を簡単に追跡するために使用されるため、イメージ内で実際に何が変更されたかをよりよく理解できます。
これにより、パッケージバージョンの非互換性を見つける時間を大幅に節約でき、適切な回避策が見つかるまで、最新のコンテナイメージでアプリケーションを再構築するか、古いバージョンをそのまま使用するかを決定できます。
また、コンテナイメージの新しいビルドでアプリケーションが機能するかどうかを簡単に調べるのにも役立ちます。
Container-diffは、コンテナイメージで以下を分析します。
- Docker Image History、
- 画像ファイルシステム
- 画像サイズ
- Aptパッケージ
- Rpmパッケージ
- pipパッケージ
- npmパッケージ。
それでは、Container-diffをインストールする方法と、それを使用してコンテナイメージを比較する方法を見てみましょう。
LinuxにContainer-diffをインストールする
UbuntuシステムでContainer-diffをテストしました。ただし、Debianやその他のUbuntuバリアント、およびその他のLinuxディストリビューションでも動作するはずです。
まず、Dockerがインストールされていることを確認します。まだインストールしていない場合は、次のリンクを参照してください。
- UbuntuにDockerをインストールする方法
Dockerをインストールしたら、次のコマンドを使用してLinuxシステムにContainer-diffをインストールします。
$ curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64
$ sudo install container-diff-linux-amd64 /usr/local/bin/container-diff
または、sudoを使用したくない場合は、次を実行します:
$ curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64
$ mkdir -p "$HOME/bin"
$ export PATH="$PATH:$HOME/bin"
$ install container-diff-linux-amd64 $HOME/bin/container-diff
Arch Linuxを使用している場合は、次のコマンドを使用してContainer-diffをインストールできます。
$ sudo pacman -S container-diff
コンテナ画像の分析
まず、 Google Container Registryに保存されているDebian9などのコンテナイメージを分析しましょう。 。
$ container-diff analyze gcr.io/google-appengine/debian9:latest
出力例:
Retrieving image gcr.io/google-appengine/debian9:latest from source Cloud Registry Retrieving analyses -----Apt----- Packages found in gcr.io/google-appengine/debian9:latest: NAME VERSION SIZE -adduser 3.115 849K -apt 1.4.8 3.5M -base-files 9.9 deb9u2 333K -base-passwd 3.5.43 229K -bash 4.4-5 5.7M -bsdutils 1:2.29.2-1 238K -ca-certificates 20161130 nmu1 468K -coreutils 8.26-3 14.7M -dash 0.5.8-2.4 204K -debconf 1.5.61 558K -debian-archive-keyring 2017.5 118K -debianutils 4.8.1.1 213K -diffutils 1:3.5-3 1.3M -dpkg 1.18.24 6.6M -e2fslibs 1.43.4-2 449K -e2fsprogs 1.43.4-2 3.9M -findutils 4.6.0 git+20161106-2 1.8M -gcc-6-base 6.3.0-18 209K -gpgv 2.1.18-8~deb9u1 721K -grep 2.27-2 1.1M -gzip 1.6-5 b1 231K -hostname 3.18 b1 47K -init-system-helpers 1.48 131K -libacl1 2.2.52-3 b1 62K -libapt-pkg5.0 1.4.8 3M -libattr1 1:2.4.47-2 b2 42K -libaudit-common 1:2.6.7-2 30K -libaudit1 1:2.6.7-2 150K -libblkid1 2.29.2-1 367K -libbz2-1.0 1.0.6-8.1 96K -libc-bin 2.24-11 deb9u1 3.3M -libc6 2.24-11 deb9u1 10.4M -libcap-ng0 0.7.7-3 b1 43K -libcomerr2 1.43.4-2 83K -libdb5.3 5.3.28-12 deb9u1 1.8M -libdebconfclient0 0.227 67K -libfdisk1 2.29.2-1 469K -libgcc1 1:6.3.0-18 108K -libgcrypt20 1.7.6-2 deb9u2 1.2M -libgpg-error0 1.26-2 572K -liblz4-1 0.0~r131-2 b1 93K -liblzma5 5.2.2-1.2 b1 339K -libmount1 2.29.2-1 403K -libncursesw5 6.0 20161126-1+deb9u1 347K -libpam-modules 1.1.8-3.6 874K -libpam-modules-bin 1.1.8-3.6 220K -libpam-runtime 1.1.8-3.6 1016K -libpam0g 1.1.8-3.6 229K -libpcre3 2:8.39-3 668K -libselinux1 2.6-3 b3 209K -libsemanage-common 2.6-2 39K -libsemanage1 2.6-2 291K -libsepol1 2.6-2 653K -libsmartcols1 2.29.2-1 257K -libss2 1.43.4-2 95K -libssl1.1 1.1.0f-3 deb9u1 3.4M -libstdc++6 6.3.0-18 2M -libsystemd0 232-25 deb9u1 652K -libtinfo5 6.0 20161126-1+deb9u1 478K -libudev1 232-25 deb9u1 222K -libustr-1.0-1 1.0.4-6 258K -libuuid1 2.29.2-1 107K -login 1:4.4-4.1 2.7M -lsb-base 9.20161125 49K -mawk 1.3.3-17 b3 183K -mount 2.29.2-1 444K -multiarch-support 2.24-11 deb9u1 220K -ncurses-base 6.0 20161126-1+deb9u1 340K -ncurses-bin 6.0 20161126-1+deb9u1 536K -netbase 5.4 44K -openssl 1.1.0f-3 deb9u1 1.2M -passwd 1:4.4-4.1 2.4M -perl-base 5.24.1-3 deb9u2 7.4M -sed 4.4-1 799K -sensible-utils 0.0.9 110K -sysvinit-utils 2.88dsf-59.9 110K -tar 1.29b-1.1 2.7M -tzdata 2017c-0 deb9u1 2.9M -util-linux 2.29.2-1 3.5M -zlib1g 1:1.2.8.dfsg-5 156K>
ご覧のとおり、Container-diffは--type
なしでAPT分析を表示します フラグが指定されています。
利用可能なアナライザーのリストは次のとおりです。
- -type =history [History]
- -type =file[ファイルシステム]
- -type =pip [Pip]
- -type =apt [Apt]
- -type =node [Node]
以下のように、一度に複数のアナライザーを実行できます。
$ container-diff analyze gcr.io/google-appengine/debian9:latest --type=history --type=apt --type=file
Container-diffを使用してコンテナイメージを比較する
2つのコンテナイメージを比較するには、次のコマンドを使用します。
$ container-diff diff gcr.io/google-appengine/debian9:latest gcr.io/google-appengine/debian9:2017-10-18-191738
ここでは、最新のDebian9ビルドイメージと2017年10月18日にビルドされたDebian9イメージの2つのコンテナイメージを比較しています。
出力例:
Starting diff on images gcr.io/google-appengine/debian9:latest and gcr.io/google-appengine/debian9:2017-10-18-191738, using differs: [apt] Retrieving image gcr.io/google-appengine/debian9:2017-10-18-191738 from source Cloud Registry Retrieving image gcr.io/google-appengine/debian9:latest from source Cloud Registry Computing diffs -----Apt----- Packages found only in gcr.io/google-appengine/debian9:latest: None Packages found only in gcr.io/google-appengine/debian9:2017-10-18-191738: None Version differences: PACKAGE IMAGE1 (gcr.io/google-appengine/debian9:latest) IMAGE2 (gcr.io/google-appengine/debian9:2017-10-18-191738) -libssl1.1 1.1.0f-3 deb9u1, 3.4M 1.1.0f-3, 3.4M -openssl 1.1.0f-3 deb9u1, 1.2M 1.1.0f-3, 1.2M -tzdata 2017c-0 deb9u1, 2.9M 2017b-1, 2.9M
出力からわかるように、最新のビルドでは3つのパッケージが更新されています。
2つの画像に違いがない場合は、次のような出力が表示されます。
Computing diffs -----Apt----- Packages found only in gcr.io/google-appengine/debian9:latest: None Packages found only in gcr.io/google-appengine/debian9:2017-11-27-220229: None Version differences: None
すでに述べたように、デフォルトでは、--type
はありません フラグが指定されている場合、container-diffはAptパッケージ分析を実行します。
以下に示すように、一度に複数のアナライザーを実行できます。
$ container-diff diff gcr.io/google-appengine/debian9:latest gcr.io/google-appengine/debian9:2017-10-18-191738 --type=history --type=apt --type=node
ここでは、履歴という3つのアナライザーを実行しています。 、 apt 、およびノード 。
出力例:
Starting diff on images gcr.io/google-appengine/debian9:latest and gcr.io/google-appengine/debian9:2017-10-18-191738, using differs: [history apt node] Retrieving image gcr.io/google-appengine/debian9:2017-10-18-191738 from source Cloud Registry Retrieving image gcr.io/google-appengine/debian9:latest from source Cloud Registry Computing diffs -----Apt----- Packages found only in gcr.io/google-appengine/debian9:latest: None Packages found only in gcr.io/google-appengine/debian9:2017-10-18-191738: None Version differences: PACKAGE IMAGE1 (gcr.io/google-appengine/debian9:latest) IMAGE2 (gcr.io/google-appengine/debian9:2017-10-18-191738) -libssl1.1 1.1.0f-3 deb9u1, 3.4M 1.1.0f-3, 3.4M -openssl 1.1.0f-3 deb9u1, 1.2M 1.1.0f-3, 1.2M -tzdata 2017c-0 deb9u1, 2.9M 2017b-1, 2.9M -----History----- Docker history lines found only in gcr.io/google-appengine/debian9:latest: None Docker history lines found only in gcr.io/google-appengine/debian9:2017-10-18-191738: None -----Node----- Packages found only in gcr.io/google-appengine/debian9:latest: None Packages found only in gcr.io/google-appengine/debian9:2017-10-18-191738: None Version differences: None
以下に示すように、ローカルに保存された画像をリモート画像と比較することもできます。
$ container-diff diff daemon://modified_debian:latest remote://gcr.io/google-appengine/debian9:latest
詳細については、以下のContainer-diff公式リンクを参照してください。