Bird
Raised Fist0
Nginxdevops~20 mins

Official Nginx Docker image - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Nginx Docker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Nginx container startup log
You run the command docker run --name webserver -d nginx. What is the expected output of docker logs webserver?
Anginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
B
2024/01/01 00:00:00 [notice] 1#1: using the "epoll" event method
2024/01/01 00:00:00 [notice] 1#1: nginx/1.25.0
2024/01/01 00:00:00 [notice] 1#1: start worker processes
2024/01/01 00:00:00 [notice] 1#1: start worker process 7
C
Error: Cannot find image 'nginx:latest' locally
Pulling from library/nginx
Digest: sha256:abcdef1234567890
Status: Downloaded newer image for nginx:latest
Ddocker: command not found
Attempts:
2 left
💡 Hint
Check the typical startup log messages for the official Nginx container.
❓ Configuration
intermediate
1:30remaining
Mounting custom Nginx config in Docker
You want to run the official Nginx Docker container with your own nginx.conf file located at /home/user/nginx.conf. Which docker run command correctly mounts this config to override the default?
Adocker run -d -p 80:80 -v /home/user/nginx.conf:/etc/nginx/conf.d/nginx.conf:ro nginx
Bdocker run -d -p 80:80 -v /etc/nginx/nginx.conf:/home/user/nginx.conf:ro nginx
Cdocker run -d -p 80:80 -v /home/user/nginx.conf:/usr/local/nginx/conf/nginx.conf:ro nginx
Ddocker run -d -p 80:80 -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro nginx
Attempts:
2 left
💡 Hint
The official Nginx image expects the main config at /etc/nginx/nginx.conf.
❓ Troubleshoot
advanced
1:30remaining
Nginx container fails to start with port binding error
You run docker run -d -p 80:80 nginx but the container exits immediately. Checking logs shows:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
What is the most likely cause?
AThe Docker daemon is not running
BThe container lacks permission to bind to port 80 inside the container
CAnother process on the host is already using port 80
DThe Docker image is corrupted and missing Nginx binaries
Attempts:
2 left
💡 Hint
Port binding errors usually mean the port is busy on the host machine.
🔀 Workflow
advanced
2:00remaining
Updating Nginx container with zero downtime
You have a running Nginx container named webserver. You want to update it to a newer Nginx image version without downtime. Which workflow is best?
APull new image, start new container on different ports, switch traffic via load balancer, then stop old container
BPull new image, stop current container, start new container with same ports and volumes
CRemove old container, pull new image, start new container with same ports
DRestart Docker daemon, then pull new image and start new container
Attempts:
2 left
💡 Hint
Zero downtime means traffic must not be interrupted during update.
✅ Best Practice
expert
2:00remaining
Securing Nginx Docker container with least privileges
Which practice best improves security by running the official Nginx Docker container with least privileges?
AUse the <code>--user</code> flag to run Nginx as a non-root user inside the container
BRun the container as root user to avoid permission issues
CDisable all logging to prevent sensitive data exposure
DRun the container with <code>--privileged</code> flag for full access
Attempts:
2 left
💡 Hint
Running as non-root inside containers is a common security best practice.

Practice

(1/5)
1. What is the primary purpose of the official Nginx Docker image?
easy
A. To quickly run Nginx inside a container for web serving
B. To build custom Linux kernels
C. To manage databases inside containers
D. To create virtual machines

Solution

  1. Step 1: Understand the role of Nginx

    Nginx is a web server used to serve websites and handle web traffic.
  2. Step 2: Recognize the Docker image purpose

    The official Nginx Docker image allows running Nginx easily inside containers for web serving.
  3. Final Answer:

    To quickly run Nginx inside a container for web serving -> Option A
  4. Quick Check:

    Official Nginx Docker image = Quick Nginx container [OK]
Hint: Nginx image runs web server in container fast [OK]
Common Mistakes:
  • Confusing Nginx with database or VM tools
  • Thinking it builds Linux kernels
  • Assuming it manages virtual machines
2. Which Docker command correctly runs the official Nginx image exposing port 80 on the host?
easy
A. docker run -p 80 nginx
B. docker run -p 8080:80 nginx
C. docker run -p 80:80 nginx
D. docker run nginx -p 80:80

Solution

  1. Step 1: Understand Docker port mapping syntax

    The correct syntax is docker run -p hostPort:containerPort image.
  2. Step 2: Match the command to expose port 80 on host

    docker run -p 80:80 nginx uses -p 80:80 which maps host port 80 to container port 80 correctly.
  3. Final Answer:

    docker run -p 80:80 nginx -> Option C
  4. Quick Check:

    Port mapping syntax = -p hostPort:containerPort [OK]
Hint: Use -p hostPort:containerPort to expose ports [OK]
Common Mistakes:
  • Omitting container port in -p option
  • Placing -p after image name
  • Using wrong port numbers
3. What will be the result of running this command?
docker run --rm -p 8080:80 nginx

Then accessing http://localhost:8080 in a browser?
medium
A. Connection refused error
B. You will see the default Nginx welcome page
C. 404 Not Found error
D. Docker container will fail to start

Solution

  1. Step 1: Analyze the Docker run command

    The command runs Nginx container mapping host port 8080 to container port 80, with --rm to remove container after exit.
  2. Step 2: Understand Nginx default behavior

    Nginx serves a default welcome page on port 80 if no custom config is provided.
  3. Final Answer:

    You will see the default Nginx welcome page -> Option B
  4. Quick Check:

    Default Nginx page served on mapped port [OK]
Hint: Default Nginx page shows if no config mounted [OK]
Common Mistakes:
  • Expecting 404 without custom config
  • Thinking container fails without volumes
  • Confusing port 80 with 8080 inside container
4. You tried to run:
docker run -p 80:80 nginx

but got an error: port is already allocated. What is the best fix?
medium
A. Stop the process using port 80 or use a different host port
B. Change the container port to 8080
C. Remove the Nginx image and pull again
D. Run the container without port mapping

Solution

  1. Step 1: Understand the error meaning

    "port is already allocated" means host port 80 is in use by another process.
  2. Step 2: Choose a fix for port conflict

    Stopping the process using port 80 or mapping to a different host port avoids conflict.
  3. Final Answer:

    Stop the process using port 80 or use a different host port -> Option A
  4. Quick Check:

    Port conflict fix = stop process or change host port [OK]
Hint: Port conflict means host port busy; change or free it [OK]
Common Mistakes:
  • Changing container port instead of host port
  • Deleting image won't fix port conflict
  • Running without port mapping disables access
5. You want to customize Nginx by using your own nginx.conf file located at /home/user/nginx.conf. Which Docker command correctly mounts this config into the container?
hard
A. docker run -v /etc/nginx/nginx.conf:/home/user/nginx.conf -p 8080:80 nginx
B. docker run -v /home/user/nginx.conf:/usr/local/nginx/nginx.conf -p 8080:80 nginx
C. docker run -v /home/user/nginx.conf:/etc/nginx/conf.d/nginx.conf -p 8080:80 nginx
D. docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro -p 8080:80 nginx

Solution

  1. Step 1: Identify correct Nginx config path inside container

    The main config file path in official Nginx image is /etc/nginx/nginx.conf.
  2. Step 2: Use volume mount syntax to map host config

    Mount host file /home/user/nginx.conf to container path /etc/nginx/nginx.conf with read-only flag :ro.
  3. Final Answer:

    docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro -p 8080:80 nginx -> Option D
  4. Quick Check:

    Mount host config to /etc/nginx/nginx.conf with :ro [OK]
Hint: Mount config to /etc/nginx/nginx.conf with :ro for safety [OK]
Common Mistakes:
  • Reversing source and target paths in -v option
  • Mounting to wrong container config directory
  • Omitting :ro to prevent accidental changes
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