[ad_1]
在本教程中,我们将学习什么是 Container-diff,如何在各种 Linux 发行版中安装 Container-diff,最后如何使用 Container-diff 分析和比较容器镜像。
内容
介绍
对于那些在容器上构建应用程序的人来说,我有一个好消息。
想象一下这个场景。 你是一名软件开发人员。 您正在使用由其他人维护的运行时容器映像上的应用程序。
在开发过程中,容器镜像的原始创建者发布了该基础镜像的新版本以及更新的系统包。
您下载更新的基础映像并继续在其上重建您的应用程序。 突然,您的应用程序停止工作。
您已成功使其在上一个映像中运行,但您的应用程序在最新的基础映像中无法运行。
您也很确定该应用程序在基础映像中先前版本的系统包上运行良好,但您不知道是哪一个。 这是哪里 “容器差异” 进来帮忙。
什么是容器差异?
Container-diff 是一个开源工具,来自 谷歌 这可以帮助您分析和比较托管在 谷歌云平台.
Container-diff,用于轻松跟踪两个基础镜像之间发生的变化,以便您更好地了解镜像内部真正发生的变化。
这将为您节省大量查找软件包版本不兼容的时间,并且您可以决定是在最新的容器映像上重建应用程序还是坚持使用旧版本,直到找到合适的解决方法。
它还可以帮助您轻松检查您的应用程序是否可以在容器映像的新版本上运行。
Container-diff 分析容器镜像中的以下内容。
- Docker镜像历史,
- 图像文件系统,
- 图片大小,
- 易于包装,
- RPM包,
- 点包,
- 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
分析容器镜像
首先,让我们分析一个容器镜像,例如 Debian 9,它存储在 谷歌容器注册.
$ 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 显示 APT 分析,没有 --type
指定的标志。
可用分析器列表是;
- –type=历史 [History]
- –type=文件 [File System]
- –type=pip [Pip]
- –type=apt [Apt]
- –type=节点 [Node]
您可以一次运行多个分析器,如下所示。
$ container-diff analyze gcr.io/google-appengine/debian9:latest --type=history --type=apt --type=file
使用 Container-diff 比较容器镜像
要比较两个容器映像,请使用以下命令:
$ container-diff diff gcr.io/google-appengine/debian9:latest gcr.io/google-appengine/debian9:2017-10-18-191738
在这里,我比较了两个容器镜像,最新的 Debian 9 构建镜像和 2017 年 18 月 10 日构建的 Debian 9 镜像。
样本输出:
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
正如您在输出中看到的,在最新版本中更新了三个包。
如果两个图像之间没有差异,您将看到如下所示的输出。
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
在这里,我正在运行三个分析器,即 历史, 易于, 和 节点.
样本输出:
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 官方链接。
资源:
- 谷歌开源博客
- 容器差异 Github 存储库
CLI命令行比较容器图像Container-diffDockerGoogleGoogle Cloud PlatformLinuxLinux Containers开源
[ad_2]