DCA practice question 6 of 25

Will this command mount the host's '/data' directory to the ubuntu container in read-only mode? Solution: 'docker run --volume /data:/mydata:ro ubuntu'

Full set: 191 questions
Answer options
A: Yes Correct answer
B: No
Correct Answer:
A. Yes
Explanation

The docker run command uses the --volume (or -v) flag to mount a host directory into a container. The syntax is host-src:container-dest:options. The provided command correctly specifies the host directory /data, the container directory /mydata, and the ro option. The ro option explicitly mounts the volume in read-only mode, preventing the container from writing to the host's /data directory.

Why Incorrect

B. No: This is incorrect. The command syntax is valid and the ro flag is the standard, officially documented method for creating a read-only volume mount.

References

1. Docker Docs, docker run command reference, "Mount volume (-v, --read-only)": "The -v or --volume flag takes a field with 3 fields, separated by colon characters (:). [host-src]:[container-dest]:[options]... The options are a comma-separated list, such as ro".

2. Docker Docs, "Use volumes", Section: "Use a read-only volume": "For some development workflows, you want the container to be able to write to the bind mount so that changes are propagated back to the Docker host. At other times, you want the container to only have read access. To mount a bind mount or volume as read-only, add :ro as an option at the end of the flag."

Scroll to Top