0
0
Dockerdevops~30 mins

Image size and minimal base images in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Image size and minimal base images
📖 Scenario: You are working on a Docker project where keeping the image size small is important for faster downloads and efficient storage. You will create a Dockerfile using a minimal base image and add a simple file to it.
🎯 Goal: Build a Docker image using a minimal base image alpine and add a text file hello.txt with the content Hello, Docker!. Then display the image size using Docker commands.
📋 What You'll Learn
Create a Dockerfile starting with the alpine base image
Add a file named hello.txt with the exact content Hello, Docker!
Use a command to display the size of the built Docker image
💡 Why This Matters
🌍 Real World
Keeping Docker images small helps in faster deployment, less storage use, and quicker updates in real projects.
💼 Career
Understanding minimal base images and image size is essential for DevOps engineers to optimize containerized applications.
Progress0 / 4 steps
1
Create a minimal Dockerfile with alpine base
Create a file named Dockerfile with the first line exactly FROM alpine to use the minimal Alpine Linux base image.
Docker
Need a hint?

The first line in a Dockerfile specifies the base image. Alpine is a very small Linux image.

2
Add a text file with content
Add these two lines to the Dockerfile: RUN echo "Hello, Docker!" > /hello.txt to create the file inside the image.
Docker
Need a hint?

Use the RUN command to execute shell commands inside the image during build.

3
Build the Docker image with a tag
Write the exact command to build the Docker image with tag hello-alpine using the current directory as context: docker build -t hello-alpine .
Docker
Need a hint?

The docker build command creates the image from the Dockerfile.

4
Display the size of the built image
Write the exact command to show the size of the image named hello-alpine: docker images hello-alpine --format "{{.Repository}}: {{.Size}}"
Docker
Need a hint?

This command lists images filtered by name and shows their size in a simple format.