Creating a Minimally Sized Docker Image

dockerThis is a follow up to the Publishing a Static AngularJS Application with Docker post.

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:

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:

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

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

UPDATE (12-Jun-17): Here's an even smaller image: Stuffing Angular into a Tiny Docker Container (< 2 MB)

This entry was posted in Programming, Tools and tagged . Bookmark the permalink.

3 Responses to Creating a Minimally Sized Docker Image

  1. suresh says:

    Hi,

    I tried exact steps, container starting and exiting imediately. Not sure why.

  2. sandeep says:

    root@ip-172-31-31-158:~/docker# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    835ba0876c45 000cd50a6e83 “httpd -D FOREGROUND” 13 seconds ago Exited (1) 12 seconds ago webserver

  3. Rahul says:

    I am trying to run these commands directly instead of running them as a Dockerfile image. But I am getting error related to servername when trying to start apache. Any idea how this can be addressed?

Leave a Reply

Your email address will not be published. Required fields are marked *