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?
✗ Incorrect
WORKDIR sets the directory where commands run inside the container.
If the directory in WORKDIR does not exist, what does Docker do?
✗ Incorrect
Docker creates the directory if it does not exist.
What is the working directory after these instructions?
WORKDIR /usr
WORKDIR local
✗ Incorrect
The second WORKDIR is relative, so it becomes /usr/local.
Can you use multiple WORKDIR instructions in one Dockerfile?
✗ Incorrect
Multiple WORKDIR instructions are allowed and update the directory.
Which instruction uses the current WORKDIR as base for relative paths?
✗ Incorrect
All these instructions use the current WORKDIR for relative paths.
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.