0
0
Dockerdevops~30 mins

Minimizing layers in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Minimizing layers in Docker images
📖 Scenario: You are creating a Docker image for a simple web application. To keep the image small and efficient, you want to minimize the number of layers in your Dockerfile.
🎯 Goal: Build a Dockerfile that installs necessary packages and copies application files using as few layers as possible.
📋 What You'll Learn
Create a Dockerfile starting from the official Python 3.12 image
Install curl and vim packages in a single layer
Copy the application files from the local app/ folder to the image
Use only one RUN command total to minimize layers
💡 Why This Matters
🌍 Real World
Minimizing Docker image layers helps reduce image size and speeds up deployment in real projects.
💼 Career
Understanding how to write efficient Dockerfiles is a key skill for DevOps engineers and developers working with containers.
Progress0 / 4 steps
1
Create the base Dockerfile
Write a Dockerfile starting with the line FROM python:3.12-slim to use the official Python 3.12 slim image as the base.
Docker
Need a hint?

The first line in a Dockerfile specifies the base image using FROM.

2
Add a single RUN command to install packages
Add a RUN command that updates the package list and installs curl and vim together using apt-get. Use apt-get update and apt-get install -y curl vim combined with && to keep it in one layer.
Docker
Need a hint?

Use one RUN command with && to chain update and install commands.

3
Copy application files in one layer
Add a COPY command to copy the local app/ folder into the image at /app. This should be a separate layer after the RUN command.
Docker
Need a hint?

Use COPY to add files from your computer to the image.

4
Combine cleanup with install to minimize layers
Modify the RUN command to also clean up the apt cache by adding rm -rf /var/lib/apt/lists/* after installing packages, all in the same RUN command to keep layers minimal.
Docker
Need a hint?

Cleaning up apt cache in the same RUN command reduces image size and layers.