0
0
Nginxdevops~20 mins

Volume mounting for configs in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Volume Mounting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Nginx container with volume mount for custom config

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?

AIt mounts the host directory <code>/home/user/nginx.conf</code> as a volume inside the container at <code>/etc/nginx/nginx.conf</code>.
BIt copies the host file <code>/home/user/nginx.conf</code> into the container's <code>/etc/nginx/nginx.conf</code> and allows writing inside the container.
CIt mounts the host file <code>/home/user/nginx.conf</code> as the container's <code>/etc/nginx/nginx.conf</code> file in read-only mode.
DIt creates a new empty file <code>/etc/nginx/nginx.conf</code> inside the container and ignores the host file.
Attempts:
2 left
💡 Hint

Look at the -v syntax: host_path:container_path:mode.

🧠 Conceptual
intermediate
1:30remaining
Purpose of volume mounting config files in nginx container

Why do we mount configuration files from the host into an nginx container instead of baking them into the image?

ABecause nginx containers cannot run without volume mounts.
BTo allow easy updates to configs without rebuilding the image or restarting the container.
CTo increase container startup time by loading configs externally.
DTo prevent nginx from reading any configuration at all.
Attempts:
2 left
💡 Hint

Think about how you update settings in real life without changing the whole product.

Configuration
advanced
2:30remaining
Correct Docker Compose volume syntax for nginx config

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?

Nginx
services:
  web:
    image: nginx
    ports:
      - "8080:80"
    volumes:
A- ./nginx.conf:/etc/nginx/nginx.conf:rw
B- /etc/nginx/nginx.conf:./nginx.conf:ro
C- ./nginx.conf:/etc/nginx/nginx.conf
D- ./nginx.conf:/etc/nginx/nginx.conf:ro
Attempts:
2 left
💡 Hint

Remember the format is host_path:container_path:mode.

Troubleshoot
advanced
2:00remaining
Nginx container ignores mounted config file changes

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?

ANginx needs to be reloaded or restarted inside the container to apply config changes.
BDocker does not support mounting files, only directories.
CThe volume mount is read-only, so changes are blocked.
DThe container automatically reloads configs every 5 minutes, so wait longer.
Attempts:
2 left
💡 Hint

Think about how software applies config changes after editing files.

Best Practice
expert
3:00remaining
Secure volume mounting of nginx configs in production

In a production environment, what is the best practice to securely mount nginx configuration files into containers?

AMount config files as read-only volumes and restrict host file permissions to trusted users only.
BMount config files as read-write volumes so containers can modify configs dynamically.
CBake configs into the container image and avoid volume mounts entirely.
DUse anonymous volumes without specifying host paths to prevent host access.
Attempts:
2 left
💡 Hint

Consider security and immutability principles for production.