0
0
Dockerdevops~5 mins

Combining RUN commands in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of combining RUN commands in a Dockerfile?
Combining RUN commands helps reduce the number of image layers, making the Docker image smaller and more efficient.
Click to reveal answer
beginner
How do you combine multiple RUN commands in a Dockerfile?
You combine them using shell operators like && to run commands sequentially in one RUN instruction.
Click to reveal answer
beginner
Example: What does this Dockerfile line do?<br>
RUN apt-get update && apt-get install -y curl
It updates the package list and then installs curl in one layer, reducing image size and build time.
Click to reveal answer
intermediate
Why should you use && instead of ; when combining RUN commands?
Using && ensures the next command runs only if the previous one succeeds, preventing errors from being ignored.
Click to reveal answer
intermediate
What is a downside of combining too many commands in one RUN instruction?
If one command fails, the whole RUN fails, and debugging can be harder because all commands are in one layer.
Click to reveal answer
What does combining RUN commands with && in a Dockerfile help achieve?
AIgnore errors in commands
BReduce image layers and size
CRun commands in parallel
DAutomatically cache commands
Which operator ensures the next command runs only if the previous command succeeds?
A&&
B;
C|
D||
What happens if you use multiple RUN commands separately instead of combining them?
ACombines commands automatically
BReduces image size
CCreates more image layers
DRuns commands faster
Which is a good practice when combining RUN commands?
AUse && to chain commands
BUse ; to separate commands
CRun commands in separate RUN instructions
DIgnore command failures
What is a potential downside of combining many commands in one RUN?
ACommands run in parallel
BCreates too many layers
CSlower image build
DHarder to debug if a command fails
Explain why and how you would combine RUN commands in a Dockerfile.
Think about how Docker images are built in layers.
You got /3 concepts.
    Describe the benefits and drawbacks of combining multiple commands in a single RUN instruction.
    Consider both image optimization and troubleshooting.
    You got /4 concepts.