By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
The Read-Only Root Filesystem (ROFS) prevents a container from modifying the root filesystem, improving security and reducing the risk of data corruption. docker run --read-only
echo "FROM alpine:latest" > Dockerfile && echo "CMD [\"echo\", \"Hello World!\"]" >> Dockerfile
docker build -t myimage .
docker run --read-only --name mycontainer myimage
docker exec -it mycontainer echo "Hello" > /root/test.txt
docker logs mycontainer
docker rm -f mycontainer
docker rmi myimage
Purpose: Run a container with ROFS and mount a volume for data storage.Command: docker run --read-only -v /data:/data --name mycontainer myimage Flags: -v mounts a volume, --read-only enables ROFS.
docker run --read-only -v /data:/data --name mycontainer myimage
-v
--read-only
Purpose: Run a container with ROFS and bind-mount a directory from the host.Command: docker run --read-only -v /host/data:/data --name mycontainer myimage Flags: -v mounts a volume, --read-only enables ROFS.
docker run --read-only -v /host/data:/data --name mycontainer myimage
Purpose: Run a container with ROFS and mount a tmpfs filesystem for temporary storage.Command: docker run --read-only -v /tmp:/tmp --name mycontainer myimage Flags: -v mounts a volume, --read-only enables ROFS.
docker run --read-only -v /tmp:/tmp --name mycontainer myimage
Error message or symptom: The container fails to start due to a write error.Why it happens: The container is trying to write to the root filesystem, which is read-only.One-line fix: docker run --read-only -v /data:/data myimage
docker run --read-only -v /data:/data myimage
Error message or symptom: The container fails to start due to a volume mount error.Why it happens: The volume mount is not properly configured.One-line fix: docker run --read-only -v /host/data:/data myimage
docker run --read-only -v /host/data:/data myimage
Error message or symptom: The container fails to start due to a bind-mount error.Why it happens: The bind-mount is not properly configured.One-line fix: docker run --read-only -v /host/data:/data myimage
Situation: You want to check if a container is running with ROFS.Command: docker inspect --format '{{.Config.Readonly}}' mycontainer Correct response: true
docker inspect --format '{{.Config.Readonly}}' mycontainer
true
Situation: You want to check if a container has a volume mounted.Command: docker inspect --format '{{.Mounts}}' mycontainer Correct response: [{"Name":"data","Mountpoint":"/data","Source":"/host/data","Type":"bind","RW":true}]
docker inspect --format '{{.Mounts}}' mycontainer
[{"Name":"data","Mountpoint":"/data","Source":"/host/data","Type":"bind","RW":true}]
Situation: You want to check if a container has a tmpfs mount.Command: docker inspect --format '{{.Mounts}}' mycontainer Correct response: [{"Name":"tmp","Mountpoint":"/tmp","Source":"tmpfs","Type":"tmpfs","RW":true}]
[{"Name":"tmp","Mountpoint":"/tmp","Source":"tmpfs","Type":"tmpfs","RW":true}]
• --read-only flag: enables ROFS • -v flag: mounts a volume • --name flag: sets the container name • docker inspect: inspects a container • docker logs: displays container logs • docker rm: removes a container • docker rmi: removes an image • ? Verify with docker version for version-specific flags • ⚠️ Be careful when deleting containers and images • ⚠️ Use --read-only with caution, as it can cause issues with some applications
--name
docker inspect
docker logs
docker rm
docker rmi
docker version
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.