Challenge - 5 Problems
Port Mapping Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Understanding port mapping syntax in docker-compose
Given this snippet from a docker-compose.yml file, what port will be accessible on the host machine?
services:
web:
image: nginx
ports:
- "8080:80"Attempts:
2 left
💡 Hint
Remember the format is hostPort:containerPort
✗ Incorrect
The syntax "8080:80" means port 8080 on the host maps to port 80 inside the container. So you access the service on host port 8080.
🧠 Conceptual
intermediate2:00remaining
Effect of omitting host port in docker-compose ports
What happens if you specify only the container port in the ports section of docker-compose.yml like this?
services:
app:
image: myapp
ports:
- "5000"Attempts:
2 left
💡 Hint
Think about how Docker handles ports when host port is not specified
✗ Incorrect
When only the container port is specified, Docker assigns a random available port on the host and maps it to the container port.
❓ Troubleshoot
advanced2:00remaining
Troubleshooting port conflicts in docker-compose
You have two services in your docker-compose.yml:
What will happen when you try to start both services together?
services:
service1:
image: app1
ports:
- "8080:80"
service2:
image: app2
ports:
- "8080:80"What will happen when you try to start both services together?
Attempts:
2 left
💡 Hint
Two services cannot bind the same host port at the same time
✗ Incorrect
Port 8080 on the host cannot be used by two containers simultaneously. Docker-compose will error on the second service.
🔀 Workflow
advanced2:00remaining
Configuring multiple port mappings in docker-compose
You want to expose container ports 80 and 443 to host ports 8080 and 8443 respectively. Which docker-compose ports configuration achieves this?
Attempts:
2 left
💡 Hint
Remember the format is hostPort:containerPort
✗ Incorrect
Option A correctly maps host port 8080 to container port 80 and host port 8443 to container port 443.
✅ Best Practice
expert3:00remaining
Best practice for exposing ports in production with docker-compose
Which approach is best to securely expose a web service running in a container on port 80 to the internet using docker-compose?
Attempts:
2 left
💡 Hint
Think about security and flexibility in production environments
✗ Incorrect
Using a reverse proxy container allows better control, SSL termination, and security while forwarding requests internally.