Relative to the size of a standard Ubuntu Docker image I thought the 250MB CoreOS image was “lean”. Earlier this month I went to a Docker talk by Brian DeHamer and learned that there are much smaller Linux base images available on DockerHub. In particular, he mentioned Alpine which is only 5MB and includes a package manager.

Here are the instructions for building the same Apache server image from the previous post with Alpine.

The Dockerfile has significant changes:

Dockerfile

1

2

3

4

5

6

7

8

# Build myapp server Docker container

FROM alpine:latest

MAINTAINER MyName

RUN apk--update add apache2

RUN rm-rf/var/cache/apk/*

ENTRYPOINT["httpd"]

CMD["-D","FOREGROUND"]

COPY dist/var/www/localhost/htdocs

Explanation of differences:

line 2: The base image is alpine:latest.

lines 4-5: Unlike the CoreOS image, the base Apline image does not include Apache. These lines use the apk package manager to install Apache2 and clean up after.

lines 6-7: Runs the exec form of the Dockerfile ENTRYPOINT command. This will run httpd in the background when the image is started.

line 8: The static web content is copied to a different directory.

Building and pushing the image to DockerHub is the same as before:

Shell

1

2

$sudo docker build-tdockeruser/myapp.# This will create a 'latest' version.

$sudo docker push dockeruser/myapp

Because of the exec additions to the Dockerfile, the command line for starting the Docker image is simpler:

Shell

1

2

# Instead of 9001, use 80 or 8080 if you want to provide external access to the application

$sudo docker run-d-p9001:80--name my-app dockeruser/myapp

The resulting Docker image is only 10MB as compared to 290MB for the same content and functionality. Nice!