Skip to main content
1 of 2
masseyb
  • 146
  • 2

Old question but you can do a lot to reduce the size of your final image (RUN, COPY and ADD create layers):

# I would suggest pinning a specific version of the image that you're extending
# ubuntu:latest today may not be the same as ubuntu:latest tomorrow
FROM ubuntu:18.04

# combining the apt-get update and install RUN instructions removes layers
# all packages that you need can be installed in the same RUN (using curl instead of wget)
RUN apt-get -qq update -y && \
    apt-get -qq install -y \
        build-essential \
        curl \
        libpcre3 \
        libpcre3-dev \
        nano

# WORKDIR will create the directories if they do not already exist
# removing the RUN's removes an additional 2 layers
WORKDIR /install-files/apache/apr-1.6.5
# combine the curl | tar RUN instructions (note: versions updated)
# install apr, expat, apr-utils and httpd in a condensed fashion and purge the installation files
# the final image is 374MB without the installation files, 468MB with the installation files
RUN curl -L http://mirrors.ukfast.co.uk/sites/ftp.apache.org/apr/apr-1.6.5.tar.gz | tar xvz -C /install-files/apache && \
    ./configure && \
    make && \
    make install && \
    rm -rf /install-files/apache/apr-1.6.5

WORKDIR /install-files/apache/expat-2.2.9
RUN curl -L https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz | tar xvz -C /install-files/apache && \
    ./configure && \
    make && \
    make install && \
    rm -rf /install-files/apache/expat-2.2.9

WORKDIR /install-files/apache/apr-util-1.6.1
RUN curl -L http://mirrors.ukfast.co.uk/sites/ftp.apache.org/apr/apr-util-1.6.1.tar.gz | tar xvz -C /install-files/apache && \
    ./configure --with-apr=/usr/local/apr/ && \
    make && \
    make install && \
    rm -rf /install-files/apache/apr-util-1.6.1

WORKDIR /install-files/apache/httpd-2.4.41
RUN curl http://mirror.ox.ac.uk/sites/rsync.apache.org//httpd/httpd-2.4.41.tar.gz | tar xvz -C /install-files/apache && \
    ./configure --with-apr=/usr/local/apr --with-expat=/usr/local/expat && \
    make && \
    make install && \
    rm -rf /install-files/apache/httpd-2.4.41

WORKDIR /
RUN mkdir /tech && \ 
    ln -s /usr/local/apache2/ /tech/httpd
# 1. "Although ADD and COPY are functionally similar, generally speaking, COPY is preferred."
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy
# 2. It's common practice to name the entrypoint script "docker-entrypoint.sh"
# 3. would suggest following the principle of least privilege
# https://digitalguardian.com/blog/what-principle-least-privilege-polp-best-practice-information-security-and-compliance
# COPY preserves file permissions - set them on the host and remove the chmod layer altogether
COPY docker-entrypoint.sh /root

# finally, our ENTRYPOINT
ENTRYPOINT ["/root/docker-entrypoint.sh"]
masseyb
  • 146
  • 2