Bird
Raised Fist0
Nginxdevops~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does volume mounting with the -v flag in Docker allow you to do with nginx configuration files?
easy
A. Run nginx without any configuration files
B. Automatically update nginx to the latest version
C. Disable nginx logging inside the container
D. Use your own config files inside the container without rebuilding the image

Solution

  1. Step 1: Understand volume mounting purpose

    Volume mounting lets you link files or folders from your computer into the container.
  2. Step 2: Apply to nginx config files

    Mounting nginx config files lets nginx inside the container use your custom settings without rebuilding the image.
  3. Final Answer:

    Use your own config files inside the container without rebuilding the image -> Option D
  4. Quick Check:

    Volume mounting = Use custom configs [OK]
Hint: Mount with -v to use your config files directly [OK]
Common Mistakes:
  • Thinking volume mounting updates nginx version
  • Assuming nginx runs without config files
  • Confusing volume mounting with disabling logs
2. Which of the following is the correct syntax to mount a local nginx config file /home/user/nginx.conf into the container's config path /etc/nginx/nginx.conf as read-only?
easy
A. docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf nginx
B. docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro nginx
C. docker run -v /etc/nginx/nginx.conf:/home/user/nginx.conf:ro nginx
D. docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:rw nginx

Solution

  1. Step 1: Identify correct volume mount syntax

    The syntax is -v local_path:container_path:options. To make it read-only, use :ro.
  2. Step 2: Match local and container paths

    Local file is /home/user/nginx.conf, container path is /etc/nginx/nginx.conf, and mount should be read-only.
  3. Final Answer:

    docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro nginx -> Option B
  4. Quick Check:

    Correct syntax with :ro = docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro nginx [OK]
Hint: Use -v local:container:ro for read-only mounts [OK]
Common Mistakes:
  • Swapping local and container paths
  • Forgetting the :ro for read-only
  • Using :rw which is default but not read-only
3. Given the command:
docker run -v /configs/nginx.conf:/etc/nginx/nginx.conf:ro nginx
What will happen if you try to edit /etc/nginx/nginx.conf inside the running container?
medium
A. The file will be read-only and edits will fail
B. The file will be editable and changes saved
C. The file will be deleted after editing
D. The container will crash immediately

Solution

  1. Step 1: Understand :ro flag effect

    The :ro flag mounts the file as read-only inside the container.
  2. Step 2: Predict editing behavior

    Trying to edit a read-only file will fail because the container cannot write to it.
  3. Final Answer:

    The file will be read-only and edits will fail -> Option A
  4. Quick Check:

    :ro means read-only = edits fail [OK]
Hint: :ro means no write allowed inside container [OK]
Common Mistakes:
  • Assuming edits save despite :ro
  • Thinking file gets deleted on edit
  • Believing container crashes on edit
4. You ran this command:
docker run -v /myconfigs/nginx.conf:/etc/nginx/nginx.conf nginx
But nginx inside the container is still using the default config. What is the most likely mistake?
medium
A. The container must be run with --privileged to mount volumes
B. You forgot to add :ro to the volume mount
C. The local file path /myconfigs/nginx.conf does not exist or is incorrect
D. You need to rebuild the nginx image after mounting

Solution

  1. Step 1: Check local file existence

    If the local file path is wrong or missing, Docker mounts an empty or default file, so nginx uses default config.
  2. Step 2: Understand volume mount behavior

    Mounting requires the local file to exist. Missing :ro is not mandatory. Rebuilding image or privileged mode is unrelated.
  3. Final Answer:

    The local file path /myconfigs/nginx.conf does not exist or is incorrect -> Option C
  4. Quick Check:

    Missing local file = default config used [OK]
Hint: Check local file path exists before mounting [OK]
Common Mistakes:
  • Assuming :ro is required
  • Thinking image rebuild is needed
  • Believing privileged mode is necessary
5. You want to run nginx in Docker using a custom config directory /home/user/nginx-config with multiple config files. Which command correctly mounts the entire directory as read-only inside the container at /etc/nginx/conf.d?
hard
A. docker run -v /home/user/nginx-config:/etc/nginx/conf.d:ro nginx
B. docker run -v /home/user/nginx-config/nginx.conf:/etc/nginx/conf.d:ro nginx
C. docker run -v /home/user/nginx-config:/etc/nginx/nginx.conf:ro nginx
D. docker run -v /home/user/nginx-config:/etc/nginx/conf.d nginx

Solution

  1. Step 1: Identify directory vs file mount

    To mount multiple config files, mount the whole directory, not a single file.
  2. Step 2: Apply read-only flag and correct paths

    Mount /home/user/nginx-config to /etc/nginx/conf.d with :ro for safety.
  3. Final Answer:

    docker run -v /home/user/nginx-config:/etc/nginx/conf.d:ro nginx -> Option A
  4. Quick Check:

    Mount directory with :ro = docker run -v /home/user/nginx-config:/etc/nginx/conf.d:ro nginx [OK]
Hint: Mount whole config folder with :ro for multiple files [OK]
Common Mistakes:
  • Mounting a single file instead of directory
  • Mounting to wrong container path
  • Forgetting :ro for read-only safety
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard