ubuntu - 如何调查 Ubuntu 的两个 Docker 镜像之间的差异?

标签 ubuntu docker

Ubuntu 14.04 的 docker 镜像体积更大,有 lsb_release命令。

$ docker run -it ubuntu:14.04
root@c0384d45aba3:/# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty
root@c0384d45aba3:/# exit
exit
$ docker images ubuntu:14.04
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              14.04               7c09e61e9035        6 weeks ago         188 MB

Ubuntu 16.04的docker镜像体积更小,没有lsb_release命令。
$ docker run -it ubuntu:16.04
root@853f2dd91c36:/# lsb_release -a
bash: lsb_release: command not found
root@853f2dd91c36:/# exit
exit
$ docker images ubuntu:16.04
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              16.04               0ef2e08ed3fa        6 weeks ago         130 MB

从他们的 Dockerfiles 开始,我怎样才能找到导致这种差异的原因?

最佳答案

这是两个图像的 Dockerfile。

  • 14.04 的 Dockerfile:https://github.com/tianon/docker-brew-ubuntu-core/blob/1a5cb40f41ac4829d8c301ccd2cf3b7a13687a8b/trusty/Dockerfile
  • 16.04 的 Dockerfile:https://github.com/tianon/docker-brew-ubuntu-core/blob/1a5cb40f41ac4829d8c301ccd2cf3b7a13687a8b/xenial/Dockerfile

  • 这是这两个文件之间的唯一区别。
    -ADD ubuntu-trusty-core-cloudimg-amd64-root.tar.gz /
    +ADD ubuntu-xenial-core-cloudimg-amd64-root.tar.gz /
    

    所以现在我们下载两个 .tar.gz 文件
  • https://github.com/tianon/docker-brew-ubuntu-core/blob/1a5cb40f41ac4829d8c301ccd2cf3b7a13687a8b/trusty/ubuntu-trusty-core-cloudimg-amd64-root.tar.gz
  • https://github.com/tianon/docker-brew-ubuntu-core/blob/1a5cb40f41ac4829d8c301ccd2cf3b7a13687a8b/xenial/ubuntu-xenial-core-cloudimg-amd64-root.tar.gz

  • 确实 lsb_release 包含在 trusty 但不包含在 xenial 中。
    $ tar -tf ubuntu-trusty-core-cloudimg-amd64-root.tar.gz | grep lsb_release$
    usr/bin/lsb_release
    $ tar -tf ubuntu-xenial-core-cloudimg-amd64-root.tar.gz | grep lsb_release$
    $
    

    然后我们将两个 tarball 的内容提取到目录中,我们可以确认 trusty 大于 xenial。
    $ mkdir trusty xenial
    $ tar -xf ubuntu-trusty-core-cloudimg-amd64-root.tar.gz -C trusty
    $ tar -xf ubuntu-xenial-core-cloudimg-amd64-root.tar.gz -C xenial
    $ du -sh trusty xenial
    208M    trusty
    141M    xenial
    

    关于ubuntu - 如何调查 Ubuntu 的两个 Docker 镜像之间的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43342437/

    相关文章:

    c - 使用 valgrind 测试代码片段

    ubuntu - 在最新的 ubuntu 上编译和安装旧内核

    docker - JFrog Docker注册表未在Kubernetes中提取图像

    docker - 将具有数据的Docker容器克隆到另一个主机

    docker - docker-compose.yml中的图像从何而来?

    ruby - 视口(viewport)未在 Ubuntu Server VM 中连接

    python - chromedriver 无法在 ubuntu 服务器的 selenium+pyvirtualdisplay 中正确渲染 html 页面

    spring-boot - Kubernetes 自动缩放内存

    Docker:通过参数共享私钥

    gitolite-admin 克隆问题