如何调查Ubuntu的两个Docker镜像之间的差异?
Ubuntu 14.04的lsb_release
比较大,并且有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的lsb_release
比较小,没有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开始,我怎么能到底是什么导致这种差异?
这里是两个图像的Dockerfiles。
- Dockerfile 14.04: https : //github.com/tianon/docker-brew-ubuntu-core/blob/1a5cb40f41ac4829d8c301ccd2cf3b7a13687a8b/trusty/Dockerfile
- Dockerfile 16.04: 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被包含在可信任中,但不包含在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