Building Smaller Images with Mutli-Stage Builds

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Containers are made of layers. Compile and install operations performed in the image, add to the layers, increasing the size of the container. Instead of keeping all of those layers into the final image, you can split those steps off, and only use the finished product. Docker provides this capability through multi-stage builds. In this lab, you will build an image the usual way, and inspect the image to see how it is put together. You’ll then convert the Dockerfile to use Multi-Stage builds, and see how the new image compares.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Do Prep Work in the Image
  1. Inspect the current Dockerfile for the NotesApp image.
  2. Build the image as notesapp and tag it as version default.
  3. Inspect the default image version, to see how many layers it has, and how large the image is.
Add a Build Stage
  1. Move the install steps in the Dockerfile to a separate stage.
  2. Copy the finished installs into the final image.
Create a Smaller Image
  1. Build the image as notesapp and tag it as version multistage.
  2. Inspect the new multistage image version to see how many layers it has and how large the image is.

Additional Resources

Scenario

You have been asked to evaluate the Docker containers your company is using to try to make them more efficient. Reducing the image size will allow you to use less resources, or run more containers using the same hardware. This can save the company money, and make you look like a rock star.

Logging in to the lab environment

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

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