Module 07 of 11

Building Container Images

Lessons

About This Module

Up to now you've run images other people built. This module is about building your own, and about building them well: fast to rebuild, small to ship, and hard to attack.

A Dockerfile is a text file of instructions describing how to build an image: the base image (FROM), the commands to run at build time (RUN), the files to copy in, and the command to start (CMD). Each instruction creates a layer, so layer caching matters: put steps that rarely change, like installing dependencies, before steps that change often, like copying source code, and rebuilds reuse the cache.

Image size and security go together. Smaller base images such as Alpine carry fewer packages, and multi-stage builds let you compile in one stage and ship only the result. That means faster builds and pulls and a smaller attack surface. Watch the lessons in order, then continue on to Container Registries.

Lessons

5 videos
01

What Is a Dockerfile? How to Create and Build One

A step-by-step beginner's guide to Dockerfiles and building efficient Docker images: the file that describes your base image, dependencies, files, and startup command.

02

Dockerfile, Docker Image, Docker Container: Hands-On

A hands-on walkthrough of creating a Dockerfile, building an image from it, and running that image as a container.

03

Docker Image Best Practices: From 1.2GB to 10MB

A guide to shrinking Docker images from gigabytes down to megabytes, with practical Dockerfile changes you can apply to your own images.

04

Learn Multi-Stage Builds Easy With Examples

How multi-stage builds keep the final image small: build in one stage with all the tools, then copy only the finished output into a lean final image.

05

3 Ways to Reduce the Size of Your Docker Images

Three more techniques for trimming image size, which helps builds, pulls, and deployments and leaves less in the image for attackers to use.