0
0
Nginxdevops~20 mins

Docker Compose with Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Compose Nginx Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Nginx container port exposure
You run a Docker Compose setup with Nginx service exposing port 80. What is the output of docker-compose ps regarding the ports column?
Nginx
version: '3.8'
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
Aweb_1 nginx:latest Up 80/tcp
Bweb_1 nginx:latest Up 0.0.0.0:80->8080/tcp
Cweb_1 nginx:latest Up 0.0.0.0:8080->80/tcp
Dweb_1 nginx:latest Up 8080/tcp
Attempts:
2 left
💡 Hint
Remember the format is host_port:container_port
Configuration
intermediate
2:00remaining
Correct Nginx service restart policy in Docker Compose
Which restart policy ensures the Nginx container restarts automatically only if it crashes, but not if stopped manually?
Arestart: always
Brestart: on-failure
Crestart: no
Drestart: unless-stopped
Attempts:
2 left
💡 Hint
Think about restart only on crashes, not manual stops.
Troubleshoot
advanced
2:00remaining
Nginx container fails to start due to port conflict
You have this Docker Compose snippet for Nginx:
ports:
  - "80:80"
But the container fails to start with an error about port 80. What is the most likely cause?
AThe container's internal port 80 is blocked by firewall
BThe container image is missing the Nginx binary
CDocker Compose file version is incompatible
DAnother process on the host is already using port 80
Attempts:
2 left
💡 Hint
Check what else might be using port 80 on your computer.
🔀 Workflow
advanced
2:00remaining
Order of commands to update Nginx container with new config
You updated the Nginx config file on your host. Which sequence of commands correctly applies the changes to the running container using Docker Compose?
A3
B4,1,2
C1,4,2
D2,3
Attempts:
2 left
💡 Hint
You only changed config, not the image.
Best Practice
expert
2:00remaining
Best way to persist Nginx logs in Docker Compose
You want to keep Nginx logs on the host machine so they are not lost when the container is removed. Which Docker Compose volume configuration is best?
A
volumes:
  - ./logs:/var/log/nginx
B
volumes:
  - logs:/var/log/nginx
volumes:
  logs: {}
C
volumes:
  - /var/log/nginx
D
volumes:
  - /var/log/nginx:/var/log/nginx
Attempts:
2 left
💡 Hint
Map a host folder to container log folder.