0
0
Dockerdevops~20 mins

RUN instruction for executing commands in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RUN Instruction Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Dockerfile RUN command?
Consider this Dockerfile snippet:
FROM alpine
RUN echo Hello World

What will be the output when building this Docker image?
Docker
FROM alpine
RUN echo Hello World
AThe build logs will show 'Hello World' printed during the RUN step.
BThe container will start and print 'Hello World' automatically.
CThe RUN command will be ignored and no output will appear.
DThe image will fail to build due to syntax error in RUN command.
Attempts:
2 left
💡 Hint
RUN commands execute during image build and their output appears in build logs.
🧠 Conceptual
intermediate
1:30remaining
What does the RUN instruction do in a Dockerfile?
Choose the best description of the RUN instruction in a Dockerfile.
AIt executes commands during the image build and creates a new image layer.
BIt runs commands every time the container starts.
CIt copies files from the host to the container.
DIt sets environment variables for the container.
Attempts:
2 left
💡 Hint
RUN commands happen once during build, not at container start.
Troubleshoot
advanced
2:30remaining
Why does this RUN command fail in Dockerfile?
Given this Dockerfile snippet:
FROM ubuntu
RUN apt-get update && apt-get install -y python3 pip

What is the cause of the failure?
Docker
FROM ubuntu
RUN apt-get update && apt-get install -y python3 pip
AThe apt-get update command requires sudo inside Dockerfile.
BThe RUN command syntax is invalid; '&&' cannot be used.
CThe Ubuntu base image does not support apt-get.
DThe package name 'pip' is incorrect; it should be 'python3-pip'.
Attempts:
2 left
💡 Hint
Check package names carefully when installing with apt-get.
🔀 Workflow
advanced
2:00remaining
How to combine multiple commands in a single RUN instruction?
You want to update package lists and install curl in one RUN instruction. Which option correctly does this?
ARUN apt-get update || apt-get install -y curl
BRUN apt-get update & apt-get install -y curl
CRUN apt-get update && apt-get install -y curl
DRUN apt-get update; apt-get install -y curl
Attempts:
2 left
💡 Hint
Use command chaining to run commands sequentially only if the first succeeds.
Best Practice
expert
3:00remaining
What is the best practice to reduce Docker image layers when using RUN?
You want to install packages and clean cache in one RUN instruction to keep image size small. Which option follows best practice?
A
RUN apt-get update
RUN apt-get install -y curl
RUN rm -rf /var/lib/apt/lists/*
BRUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
C
RUN apt-get update && apt-get install -y curl
RUN rm -rf /var/lib/apt/lists/*
DRUN apt-get update; apt-get install -y curl; rm -rf /var/lib/apt/lists/*
Attempts:
2 left
💡 Hint
Combine commands with && to create a single layer and clean cache in the same RUN.