Creation of a Base Image for other Docker Images

Introduction

I prefer Ubuntu over any other distribution out there. Seems to be the least amount of hassle to get anything done with it over any other distro I’ve used and I’ve used a lot of them both professionally and for my home use.  For that reason I base all my other images on Ubuntu and towards that end I have a base Ubuntu image that I maintain and occasionally modify that all other images I create for my own use are based on.

I can just hear someone asking “what about Alpine?”   Yes I know a lot of Docker people prefer Alpine and it is a good distro.  My odgita with it came when I was trying to create a derived image with it where I had to build the application on the image build I had a hassle getting the right combination of libraries, utilities and other stuff causing me to pull out what little hair I have left.

Ubuntu “just works” from my perspective and certainly some applications seem to thrive there better than other distributions of Linux.   Don’t even talk to me about Windows anything because I don’t do Windows.

Why even create a custom base image?

My first answer would be because I am a bit of a control freak.  But that is certainly not a complete answer.  I go by the theory  “If I have to do it twice I’m automating it.”  My custom image consists of things that are going to be in common with other images derived from the base image.

What’s in this image?

For all my derived images I wan to have the following items:

  • Puppet agent;  this gives me the flexibility of using Puppet to make tweaks to application configurations over the lifespan of the application as well as items such as repository configurations, SSH/SSL keys etc.
  • Nagios NRPE server.  Allows me to monitory up/down status of the application.

Simple enough list but this will also allow me to use Jenkins later on to make updates to the installed packages on the image itself when the Ubuntu team publishes their updates.

Where can I get this image?

I have an account on Docker Hub as userid saltycowdawg.  The image you would be interested in would be saltycowdawg/ubuntu:latest.  I have not yet updated tags to this image preferring to use the “latest” tag for now.  Once I consider this ready for a new tag I plan to increment the semantic version of the image as well as the “latest” tag.

I also maintain my own Git repository (even though I’m a fan of Bit Bucket, it’s that whole control freak thing) and the base URL is http://git.berghold.net:3000/ which is going to eventually move to https://scm.berghold.net which will be documented here when it does. The current Git repository was an experiment originally and has outlived its experimental stage.  The full URL for the image definitions is here.

Keep in mind this image and its derivitives are meant to be used with Kubernetes but can also be used with “docker-compose” as well.

Getting down to business

I will just plunge right in and show the Dockerfile this image has been built with:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##########################################################################
###
### Base Ubuntu package that has the Puppet agent already installed but
### not initialized.
### -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
FROM ubuntu:18.04
LABEL MAINTAINER Peter L. Berghold <peter@berghold.net>
LABEL VERSION    7.1.0
# Arguments that can be overridden
ARG   PUPPET_DPKG=http://apt.puppetlabs.com/puppet-release-bionic.deb
ARG   OPTDIRPATH=/opt/docker-utils
ARG   START_PUPPET_AGENT=0
ARG   START_NRPE_AGENT=0
# Environmental variables to be passed to the container that are set
# by the values in the argument list.
ENV  START_PUPPET_AGENT=${START_PUPPET_AGENT}
ENV  START_NRPE_AGENT=${START_NRPE_AGENT}
# Make sure the OS is up to date
RUN apt-get update && \
    apt-get -y dist-upgrade
# Install some much needed stuff before we go further
RUN export DEBIAN_FRONTEND=noninteractive && \
    apt-get -y --no-install-recommends install wget curl  \
    libterm-ui-perl libterm-readline-perl-perl apt-utils
# Load the Puppet deb repository package
RUN cd /tmp && wget --quiet ${PUPPET_DPKG} && \
    dpkg -i $(basename ${PUPPET_DPKG} ) && \
    rm -rf $(basename ${PUPPET_DPKG})
# This is the main build
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
    apt-get -y install --no-install-recommends openssh-server openssh-client \
               openssl puppet-agent \
               nagios-nrpe-server  ntp && \
         apt-get -y remove curl wget && \
         apt-get -y autoremove  && \
         rm -rf /var/lib/apt/lists/* && \
               rm -fr /etc/localtime && \
               ln -s /usr/share/zoneinfo/America/New_York /etc/localtime && \
               echo "America/New_York" > /etc/timezone && \
         mkdir -vp ${OPTDIRPATH}/init.d

COPY docker-inits/ ${OPTDIRPATH}/init.d/

 

This image definition is very definitely going to be subject to change. For instance there are a few more ARG variables I plan to add such as which Timezone.  Currently I am being chauvinistic in my choice of America/New_York because that’s where I live.

 

Copyright Devops — In the Trenches 2019
Tech Nerd theme designed by Siteturner