0
0
Dockerdevops~20 mins

Mounting read-only volumes in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Read-Only Volume Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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"
AThe command fails with a 'Read-only file system' error.
BThe command succeeds and writes 'test' to /container/data/file.txt inside the container.
CThe container ignores the read-only flag and writes the file successfully.
DThe container crashes immediately without any error message.
Attempts:
2 left
💡 Hint
Think about what the ':ro' flag means when mounting volumes in Docker.
🧠 Conceptual
intermediate
1: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?
ATo increase the container's CPU usage.
BTo allow the container to write logs to the host system.
CTo enable the container to update configuration files on the host.
DTo prevent the container from modifying host files and improve security.
Attempts:
2 left
💡 Hint
Think about protecting host data from accidental or malicious changes.
Configuration
advanced
2: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:
A- /app/config:/config:ro
B- /app/config:/config:rw
C- /app/config:/config
D- /app/config:/config:read-only
Attempts:
2 left
💡 Hint
Docker Compose uses the same volume mount syntax as Docker CLI for read-only flag.
Troubleshoot
advanced
2: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?
AThe container image 'alpine' does not support writing to volumes.
BThe host directory '/host/data' is mounted as read-only by the host OS permissions.
CThe volume mount syntax is incorrect and defaults to read-only.
DThe Docker daemon is running in read-only mode.
Attempts:
2 left
💡 Hint
Check the permissions of the host directory being mounted.
🔀 Workflow
expert
3: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.
A4,2,1,3
B1,4,2,3
C4,1,2,3
D2,4,1,3
Attempts:
2 left
💡 Hint
Think about preparing data and permissions before running the container.