Building Container Images Using Dockerfiles

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Creating a container image by hand is possible, but it requires manual processes. There has to be a more automatic way to build images. Manual processes do not scale and are not easily version controlled. Docker provides a solution to this problem – the Dockerfile. In this lab, you will create a Dockerfile to build an image to host a static website.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Build a First Version
  1. Create a Dockerfile that uses httpd:2.4 as the base image, then runs basic package updates.
  2. Build the 0.1 version of the widgetfactory image using the Dockerfile.
  3. Inspect the image to see its size and layers.
Load the Website into the Container
  1. Remove the Apache welcome page from the image.
  2. Build version 0.2 of the widgetfactory image.
  3. Inspect both versions of the widgetfactory image to see the differences in size and layers.
  4. Add the website data to the container.
  5. Build version 0.3 of the widgetfactory image.
  6. Inspect versions 0.2 and 0.3 to see the differences in size and layers.
Run a Container from the Image
  1. Run a container from the widgetfactory:0.3 image in the terminal, to see which command it executes. Remember to publish the web server port.
  2. Stop the container running in the terminal, then start it in detached mode.
  3. View the website files in the container.
  4. Retrieve the main website page from the container and compare it to the copy on the server.
Read Me

Note: Many of the things done in this lab are intentionally inefficient, These tasks are done to demonstrate certain aspects of Docker, and highlight common pitfalls. These do not represent best practices.

Additional Resources


You have been tasked with migrating your company's website to a container, to help meet increased demand, and improve scalability.

You've performed multiple experiments with the website, and the container, but it's time to standardize the process and make it repeatable. This means you need a way to code and automate image creation. Docker provides an easy solution: the Dockerfile. Create a Dockerfile that will generate a container image for serving your website.

The Widget Factory website is available from GitHub and has already been cloned into the cloud_user's home directory. You will use this website code in the image.

Log in to the server using the credentials provided:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?