Stay on minor version of operating system
Jan Pazdziora
When building an image from Dockerfile using
docker build .
the FROM image:tag specifies the base image to be used. So it
is possible to define not just rhel, centos, or
fedora, but be more specific: rhel7.0,
centos:6.6, or fedora:20.
The subsequent
RUN yum install -y ...or
RUN yum upgrade -y ...commands will use whatever repositories are configured for yum. For Fedoras, every version has its own repos but how about operating systems that use major.minor versions? Let us test:
docker run rhel7.1 rpm -q yum
yum-3.4.3-125.el7.noarch
FROM rhel7.1 RUN yum upgrade -y yum
docker build -t rhel7.1-yum . [...] docker run rhel7.1-yum rpm -q yum yum-3.4.3-125.el7.noarch
Now with RHEL 7.0:
docker run rhel7.0 rpm -q yum
yum-3.4.3-118.el7.noarch
FROM rhel7.0 RUN yum upgrade -y yum
docker build -t rhel7.0-yum . [...] docker run rhel7.0-yum rpm -q yum yum-3.4.3-125.el7.noarch
The package got upgraded to the version from 7.1 even if we said
FROM rhel7.0. That however only means that the base image
we start with is 7.0, yum will use the 7Server directory just
like with 7.1.
To make sure yum is fixated to a particular minor version, let us set
releasever:
FROM rhel7.0 RUN echo 7.0 > /etc/yum/vars/releasever RUN yum upgrade -y yum
docker build -t rhel7.0-yum . [...] docker run rhel7.0-yum rpm -q yum yum-3.4.3-118.el7.noarch
And it works not just for installing/upgrading the yum package:
FROM rhel7.0 RUN yum install -y httpd
docker build -t rhel7.0-httpd . [...] docker run rhel7.0-httpd rpm -q httpd httpd-2.4.6-31.el7.x86_64
FROM rhel7.1 RUN yum install -y httpd
docker build -t rhel7.1-httpd . [...] docker run rhel7.1-httpd rpm -q httpd httpd-2.4.6-31.el7.x86_64
FROM rhel7.0 RUN echo 7.0 > /etc/yum/vars/releasever RUN yum install -y httpd
docker build -t rhel7.0-httpd .
[...]
docker run rhel7.0-httpd rpm -q httpd
httpd-2.4.6-19.el7_0.x86_64
This is useful especially for testing when you want to make sure you get packages from the old version and not the latest minor release.