You run this Docker command to start an nginx container with a custom config file mounted:
docker run -d -p 8080:80 -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro nginx
What will be the effect of the -v option here?
Look at the -v syntax: host_path:container_path:mode.
The -v option mounts a host file or directory into the container. Here, a single file /home/user/nginx.conf is mounted as /etc/nginx/nginx.conf inside the container. The :ro means read-only.
Why do we mount configuration files from the host into an nginx container instead of baking them into the image?
Think about how you update settings in real life without changing the whole product.
Mounting config files allows changing nginx settings by editing files on the host. This avoids rebuilding the container image and makes updates faster and simpler.
Which Docker Compose snippet correctly mounts a custom nginx config file ./nginx.conf from the project directory into the container at /etc/nginx/nginx.conf as read-only?
services:
web:
image: nginx
ports:
- "8080:80"
volumes:Remember the format is host_path:container_path:mode.
Option D correctly mounts the host file ./nginx.conf to the container path with read-only mode. Option D misses the read-only flag. Option D reverses paths. Option D sets read-write mode.
You mounted a custom nginx config file into a running container. After editing the host config file, nginx inside the container does not reflect the changes. What is the most likely cause?
Think about how software applies config changes after editing files.
Editing the config file on the host updates the file inside the container, but nginx must reload or restart to read the new config. Without reload, nginx keeps using the old settings.
In a production environment, what is the best practice to securely mount nginx configuration files into containers?
Consider security and immutability principles for production.
Mounting config files as read-only prevents accidental or malicious changes from inside the container. Restricting host file permissions protects configs from unauthorized edits. Baking configs into images reduces flexibility. Anonymous volumes do not provide config control.