B. Only updates package lists and installs curl, but does not clean files
C. Fails because rm command is invalid in RUN
D. Updates package lists, installs curl, and cleans temporary files in one layer
Solution
Step 1: Analyze the chained RUN commands
The commands update packages, install curl, then remove apt cache files in one RUN.
Step 2: Understand layer creation
All commands combined in one RUN create a single image layer with all changes.
Final Answer:
Updates package lists, installs curl, and cleans temporary files in one layer -> Option D
Quick Check:
Combined RUN commands = single layer with all steps [OK]
Hint: One RUN with && creates one layer with all commands [OK]
Common Mistakes:
Thinking each command creates a separate layer
Assuming rm command is invalid in RUN
Ignoring cleaning temporary files effect
4. You wrote this Dockerfile line:
RUN apt-get update & apt-get install -y git
What is the problem with this command?
medium
A. The & operator is correct and recommended for RUN commands
B. The single & runs commands in background, causing build errors
C. The commands will run sequentially without errors
D. The command will install git twice
Solution
Step 1: Understand the & operator in shell
Single & runs the first command in background, not waiting for completion.
Step 2: Impact on Docker build
This causes the second command to run immediately, possibly before update finishes, leading to errors.
Final Answer:
The single & runs commands in background, causing build errors -> Option B
Quick Check:
Use && not & to chain RUN commands [OK]
Hint: Use &&, not &, to chain commands in RUN [OK]
Common Mistakes:
Using & instead of && for chaining
Assuming commands run sequentially with &
Ignoring build errors caused by background commands
5. You want to install curl and git in one RUN command and clean up apt cache to keep the image small. Which Dockerfile line correctly does this?
hard
A. RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
B. RUN apt-get update; apt-get install -y curl git; rm -rf /var/lib/apt/lists/*
C. RUN apt-get update && apt-get install -y curl && apt-get install -y git && rm -rf /var/lib/apt/lists/*
D. RUN apt-get update & apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
Solution
Step 1: Combine update and install commands safely
Use && to chain update and install commands to ensure sequential success.
Step 2: Clean apt cache in the same RUN
Remove temporary files with rm -rf /var/lib/apt/lists/* in the same RUN to keep image small.
Step 3: Check options for correctness
RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/* chains all commands correctly in one RUN; others use semicolons or background & causing issues or inefficiencies.
Final Answer:
RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/* -> Option A
Quick Check:
Chain with && and clean in one RUN [OK]
Hint: Chain update, install, and cleanup with && in one RUN [OK]
Common Mistakes:
Using semicolons instead of && without error checking
Running install commands separately (inefficient)
Using & causing background execution errors
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.