0
0
Dockerdevops~15 mins

Combining RUN commands in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Combining RUN Commands in Dockerfile
📖 Scenario: You are creating a Docker image for a simple web application. To keep the image small and efficient, you want to combine multiple RUN commands into one.
🎯 Goal: Build a Dockerfile that installs curl and vim using a single RUN command.
📋 What You'll Learn
Create a Dockerfile starting from the ubuntu:20.04 base image
Use a single RUN command to update package lists and install curl and vim
Use apt-get update and apt-get install -y curl vim combined with &&
End the RUN command with rm -rf /var/lib/apt/lists/* to clean up
Print the Dockerfile content at the end
💡 Why This Matters
🌍 Real World
Combining RUN commands in Dockerfiles helps create smaller, faster, and cleaner Docker images used in real-world software deployment.
💼 Career
Understanding how to optimize Dockerfiles is a key skill for DevOps engineers and developers working with containerized applications.
Progress0 / 4 steps
1
Create the base Dockerfile
Create a Dockerfile starting with the line FROM ubuntu:20.04.
Docker
Need a hint?

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

2
Add a combined RUN command
Add a single RUN command that updates the package list with apt-get update and installs curl and vim using apt-get install -y curl vim. Combine these commands using &&.
Docker
Need a hint?

Use RUN apt-get update && apt-get install -y curl vim to combine the commands.

3
Add cleanup to the RUN command
Extend the existing RUN command to also remove the package lists by adding rm -rf /var/lib/apt/lists/* at the end, combined with &&.
Docker
Need a hint?

Use && rm -rf /var/lib/apt/lists/* to clean up after installing.

4
Print the Dockerfile content
Write a command to print the content of the Dockerfile using cat Dockerfile.
Docker
Need a hint?

Use cat Dockerfile to display the file content.