Friday, November 03, 2017

Oracle linux - building small Docker containers while using yum

Docker and more precise Docker containers are in general small. The rule for Docker containers is, keep them as small as possible. Building containers is a process where you have to look every step of the way on what you really need and what you can remove or clean. When building a container most people will depend on a mainstream base image, in our case we base most of our containers on the Oracle Linux 7 slim image which is the smallest Docker base image build upon Oracle Linux 7.

One of the rules when you build your own containers on top of the Oracle Linux 7 slim base image (rule applies for all others as well) is that you have to clean after you build. In one example we install a lot of things using yum which are needed as part of the build process. Rule is that you have to clean after you are done to ensure the resulting container is small and is not carrying unneeded things.

in our example we have totally in the beginning a run command, as shown below, that will install a number of packages during the build phase:

# Install dependencies
RUN yum -y install make gcc cc tar gzip

Right after this we initiate a number of compile and build steps. However, after those are done we can remove the installed dependencies again.

# Cleanup dependencies
RUN yum -y erase gcc cc tar gzip

Even though this is good housekeeping it is not enough to ensure your image is small. Yum will keep some files in cache which you also have to ensure are cleaned. If this is not done you will have a lot of unneeded things in your local yum cache which will make your docker image for a container much bigger than needed.

To clean the cache you will also have to ensure you have the following run command in your Dockerfile;

# clean the YUM cache.
RUN yum clean all

Making sure you remove the unneeded dependencies you installed at the end of your Dockerfile and also ensure that you can clean your yum cache will make your image shrink and will ensure you have small Docker images and Docker containers with Oracle Linux 7 in your environment. 

Thursday, November 02, 2017

Oracle Linux - getting newer versions of Docker via yum

When using Oracle Linux to run Docker you might depend by default on the Oracle YUM repository. While this is perfectly fine, the Oracle repository might be running behind with the mainstream Docker versions and you will not by default get the latest versions of Docker. As Docker introduces a lot of new features per version and you want to be using the latest stable version the way to go is to use a Docker owned repository.

For Oracle Linux 6 there is a specific repository provided by Docker. you can use this as an addition to the standard Oracle Linux repositories. The example below showcases a docker.repo file located in /etc/yum.repos.d/

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/oraclelinux/6/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

If you have this file available YUM will be checking this repository when you want to install (or update) docker to a newer version, which in some cases is a newer version than would be availabel via the public-yum.oracle.com repository.