Difficulty: Beginner
Estimated Time: 10 minutes

In the first scenario, we discussed how you could start containers based on pre-existing images from the Docker Registry. This scenario explains how to build an image based on your requirements.

For this scenario, the container will be running a static HTML application using Nginx, a high-performance web server. In the future, we'll explain how to deploy other stacks such as Node.js or ASP.NET.

The machine name Docker is running on is called docker. If you want to access any of the services, then use docker instead of localhost or

Docker Images

Docker images are built based on a Dockerfile. A Dockerfile defines all the steps required to create a Docker image with your application configured and ready to be run as a container. The image itself contains everything, from operating system to dependencies and configuration required to run your application.

Having everything within the image allows you to migrate images between different environments and be confident that if it works in one environment, then it will work in another.

The Dockerfile allows for images to be composable, enabling users to extend existing images instead of building from scratch. By building on an existing image, you only need to define the steps to setup your application. The base images can be basic operating system installations or configured systems which simply need some additional customisations.

To help you complete the steps, an environment has been created with Docker configured. The editor allows you to write a Dockerfile which defines how to build the Docker image.

In this scenario we covered how to write a Dockerfile to define how to build and configure your image to run as a Docker container. A Dockerfile is key to creating repeatable images that can define how your applications are configured and deployed in development and production.

In future scenarios will explore how you can use Dockerfile's to build images to deploy applications based on Node.JS, ASP.NET and more.

Building Container Images

Step 1 of 6

Step 1 - Base Images

All Docker images start from a base image. A base image is the same images from the Docker Registry which are used to start containers. Along with the image name, we can also include the image tag to indicate which particular version we want, by default, this is latest.

These base images are used as the foundation for your additional changes to run your application. For example, in this scenario, we require NGINX to be configured and running on the system before we can deploy our static HTML files. As such we want to use NGINX as our base image.

Dockerfile's are simple text files with a command on each line. To define a base image we use the instruction FROM <image-name>:<tag>

Task: Creating a Dockerfile

The first line of the Dockerfile should be FROM nginx:1.11-alpine

Make the change in the Dockerfile editor. Within the environment, a new Dockerfile will be created with the contents of the editor.


It's tempting to use the tag :latest however this can result in you building your image against a version which you were not expecting. We recommend that you always use a particular version number as your tag and manage the updating yourself.