ubuntu docker容器中的可用软件包版本根据主机操作系统而变化

我无法在基于Ubuntu的Docker容器中固定版本的python和nodejs。

我遇到困难的原因是因为容器中可用的软件包版本根据主机而改变。

我想通过添加以下命令在Dockerfile中指定python和nodejs debian软件包的哪些版本:

RUN apt-get -y install "python=2.7.5-5ubuntu3" build-essential "nodejs=6.1.0-1nodesource1~trusty1" vim jq 

我通过在我的OSX el-capitan笔记本电脑本地运行的ubuntu容器内运行一些apt-cache madison命令来确定这些版本string。 一切正常。 当我尝试在运行在Amazon Linux实例上的CI环境中构build相同的容器时,它会失败,因为指定的版本不可用。

这里有一些输出显示了究竟是怎么回事。

OSX El Capitan(通过docker-machine VBOX wrapper)

 $ uname -a Darwin Kyles-MacBook-Pro.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64 $ # now get into the container $ docker exec -it named_container bash root@79a839297d7e:/src# apt-cache madison nodejs nodejs | 6.1.0-1nodesource1~trusty1 | https://deb.nodesource.com/node_6.x/ trusty/main amd64 Packages nodejs | 0.10.25~dfsg2-2ubuntu1 | http://archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages nodejs | 0.10.25~dfsg2-2ubuntu1 | http://archive.ubuntu.com/ubuntu/ trusty/universe Sources nodejs | 6.1.0-1nodesource1~trusty1 | https://deb.nodesource.com/node_6.x/ trusty/main Sources root@79a839297d7e:/src# apt-cache madison python python | 2.7.5-5ubuntu3 | http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages python-defaults | 2.7.5-5ubuntu3 | http://archive.ubuntu.com/ubuntu/ trusty/main Sources 

CI环境中的序列相同 – 在AMI Linux上:

 $ uname -a Linux ip-10-250-160-248 4.4.8-20.46.amzn1.x86_64 #1 SMP Wed Apr 27 19:28:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ # now get into the container $ docker exec -it named_container bash root@8344a5f311fe:/src# apt-cache madison nodejs nodejs | 6.1.0-1nodesource1~xenial1 | https://deb.nodesource.com/node_6.x xenial/main amd64 Packages nodejs | 4.2.6~dfsg-1ubuntu4 | http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages nodejs | 4.2.6~dfsg-1ubuntu4 | http://archive.ubuntu.com/ubuntu xenial/universe Sources nodejs | 6.1.0-1nodesource1~xenial1 | https://deb.nodesource.com/node_6.x xenial/main Sources $ root@8344a5f311fe:/src# apt-cache madison python python | 2.7.11-1 | http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages python-defaults | 2.7.11-1 | http://archive.ubuntu.com/ubuntu xenial/main Sources 

这里是Dockerfile的开始,我改变了ENTRYPOINT和CMD,因为它们与这个问题无关

 FROM ubuntu MAINTAINER Kyle Zeeuwen RUN apt-get update RUN apt-get -y install curl RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - RUN apt-get -y install "python=2.7.5-5ubuntu3" build-essential "nodejs=6.1.0-1nodesource1~trusty1" vim jq CMD ["sleep", "3600"] 

所以我的问题:

  1. 我需要更改以可靠地设置python和nodejs版本,以便Docker容器构build可以在包括OSX和Linux AMI在内的一系列主机环境中工作

  2. 发生什么事情会使Ubuntu报告不同的发行版?

版本不匹配有两个可能的原因:

  1. 基本映像版本:基本映像在其中一台机器上不是最新的。 确保在构build之前运行docker pull ubuntu ,或者使用附加的--pull标志进行构build。
  2. Dockercaching: apt-get update步骤被caching,并且caching在一台机器上比另一台机器更旧。 你不应该运行apt-get update而没有任何其他命令,因为caching永远不会失效。 相反,请执行RUN apt-get update && apt-get -y install curl 。 你也可以运行docker build --no-cache来确保你不使用任何caching。

简而言之: docker build --pull --no-cache应该可以解决你的问题,但是你也应该像上面解释的那样调整你的Dockerfile。