Challenge - 5 Problems
Read-Only Volume Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the effect of this Docker run command?
Consider the command below that runs a Docker container with a volume mounted as read-only. What will be the output when the container tries to write to the mounted directory?
Docker
docker run --rm -v /host/data:/container/data:ro alpine sh -c "echo 'test' > /container/data/file.txt"
Attempts:
2 left
💡 Hint
Think about what the ':ro' flag means when mounting volumes in Docker.
✗ Incorrect
Mounting a volume with ':ro' makes the mounted directory read-only inside the container. Any attempt to write to it will fail with a 'Read-only file system' error.
🧠 Conceptual
intermediate1:30remaining
Why use read-only volume mounts in Docker?
Which of the following is the best reason to mount a volume as read-only in a Docker container?
Attempts:
2 left
💡 Hint
Think about protecting host data from accidental or malicious changes.
✗ Incorrect
Mounting volumes as read-only prevents containers from changing host files, which enhances security and stability.
❓ Configuration
advanced2:00remaining
Identify the correct Docker Compose volume mount for read-only access
Given this Docker Compose service snippet, which option correctly mounts the host directory '/app/config' as read-only inside the container at '/config'?
Docker
services:
app:
image: myapp:latest
volumes:Attempts:
2 left
💡 Hint
Docker Compose uses the same volume mount syntax as Docker CLI for read-only flag.
✗ Incorrect
The ':ro' suffix marks the volume as read-only. ':rw' is read-write (default), and 'read-only' is invalid syntax.
❓ Troubleshoot
advanced2:30remaining
Why does this container fail to write to a mounted volume despite no ':ro' flag?
A developer runs this command:
docker run --rm -v /host/data:/data alpine sh -c "echo 'hello' > /data/file.txt"
But the command fails with 'Read-only file system'. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the permissions of the host directory being mounted.
✗ Incorrect
If the host directory has read-only permissions, the container cannot write to it even if the volume is mounted without ':ro'.
🔀 Workflow
expert3:00remaining
Order the steps to safely mount a read-only volume in Docker for a production app
Arrange the following steps in the correct order to mount a read-only volume for a Docker container running a production app.
Attempts:
2 left
💡 Hint
Think about preparing data and permissions before running the container.
✗ Incorrect
First prepare data (4), then set permissions (1), run container with ':ro' (2), finally verify (3).