0
0
Dockerdevops~30 mins

Squashing layers in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Squashing Layers in Docker Images
📖 Scenario: You are working on a Docker project where you want to optimize the image size by combining multiple layers into one. This helps reduce the final image size and speeds up deployment.
🎯 Goal: Build a Dockerfile that creates a base image with multiple commands, then squash the layers into a single layer using Docker build options.
📋 What You'll Learn
Create a Dockerfile with multiple RUN commands
Add a label to the image
Use Docker build with the --squash option to combine layers
Display the final image size
💡 Why This Matters
🌍 Real World
Squashing layers helps reduce Docker image size, which saves storage and speeds up deployment in real projects.
💼 Career
Understanding layer squashing is important for DevOps roles to optimize container images and improve CI/CD pipelines.
Progress0 / 4 steps
1
Create a Dockerfile with base image and multiple RUN commands
Create a file named Dockerfile with the following content exactly: start from the alpine:latest image, then add two RUN commands: one to update the package list with apk update and another to install curl with apk add curl.
Docker
Need a hint?

Use FROM alpine:latest as the base. Then add two separate RUN lines for update and install.

2
Add a label to the Dockerfile
Add a LABEL instruction to the existing Dockerfile that sets maintainer to devops@example.com.
Docker
Need a hint?

Use LABEL maintainer="devops@example.com" exactly.

3
Build the Docker image with squashing layers
Use the Docker CLI to build the image from the current directory with the tag myapp:squashed and enable layer squashing using the --squash option.
Docker
Need a hint?

Run docker build --squash -t myapp:squashed . in your terminal to build the image with squashed layers.

4
Display the final image size
Run the Docker command to show the size of the image tagged myapp:squashed.
Docker
Need a hint?

Use docker images myapp:squashed to see the image size.