0
0
Dockerdevops~5 mins

WORKDIR instruction for directory in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the WORKDIR instruction do in a Dockerfile?
WORKDIR sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it in the Dockerfile. It changes the current directory inside the container.
Click to reveal answer
beginner
If the directory specified in WORKDIR does not exist, what happens?
Docker will create the directory automatically before setting it as the working directory.
Click to reveal answer
intermediate
How does WORKDIR affect the path for subsequent instructions in a Dockerfile?
After setting WORKDIR, all relative paths in following instructions are based on this directory, making file operations easier and clearer.
Click to reveal answer
intermediate
Can you use multiple WORKDIR instructions in a Dockerfile? What happens?
Yes, you can use multiple WORKDIR instructions. Each one changes the working directory from the previous one. If a relative path is given, it is relative to the current WORKDIR.
Click to reveal answer
intermediate
Example: What is the working directory after these instructions? WORKDIR /app WORKDIR logs
The final working directory is /app/logs because the second WORKDIR 'logs' is relative to the first '/app'.
Click to reveal answer
What does the WORKDIR instruction do in a Dockerfile?
AExposes a port for the container
BCopies files into the container
CSets the working directory for following instructions
DRuns a command inside the container
If the directory in WORKDIR does not exist, what does Docker do?
AThrows an error and stops building
BUses the root directory instead
CIgnores the instruction
DCreates the directory automatically
What is the working directory after these instructions? WORKDIR /usr WORKDIR local
A/usr/local
B/local
C/usr
D/
Can you use multiple WORKDIR instructions in one Dockerfile?
ANo, only one WORKDIR is allowed
BYes, each changes the working directory
CYes, but only the first one works
DNo, it causes a build error
Which instruction uses the current WORKDIR as base for relative paths?
AAll of the above
BRUN
CWORKDIR
DCOPY
Explain what the WORKDIR instruction does and why it is useful in a Dockerfile.
Think about how commands run inside the container.
You got /4 concepts.
    Describe what happens when you use multiple WORKDIR instructions with relative paths in a Dockerfile.
    Consider how paths combine step by step.
    You got /4 concepts.