Challenge - 5 Problems
Port Exposure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of the port mapping command?
You run the command
docker run -d -p 8080:80 nginx. What does this command do?Attempts:
2 left
💡 Hint
The format is
-p hostPort:containerPort.✗ Incorrect
The command maps port 80 inside the container to port 8080 on the host machine, so accessing localhost:8080 reaches nginx's port 80.
🧠 Conceptual
intermediate1:30remaining
Why expose ports in Docker containers?
Why do we expose ports from a Docker container to the host machine?
Attempts:
2 left
💡 Hint
Think about how you access a website running inside a container.
✗ Incorrect
Exposing ports lets the host machine send requests to the container's services, like a web server.
❓ Configuration
advanced2:00remaining
Which Docker Compose port mapping is correct?
Given this Docker Compose snippet, which option correctly maps port 5000 inside the container to port 3000 on the host?
Docker
services:
app:
image: myapp
ports:Attempts:
2 left
💡 Hint
Remember the format is
hostPort:containerPort.✗ Incorrect
The correct syntax maps host port 3000 to container port 5000, allowing access via localhost:3000.
❓ Troubleshoot
advanced2:30remaining
Why can't you access the container service on the host port?
You ran
docker run -d -p 8080:80 nginx but cannot access the web server at http://localhost:8080. What could be the reason?Attempts:
2 left
💡 Hint
Check if the service inside the container is running on the expected port.
✗ Incorrect
If the service inside the container is not listening on port 80, mapping that port won't work.
✅ Best Practice
expert3:00remaining
What is the best practice for exposing ports in production Docker containers?
Which option is the best practice for exposing ports when running Docker containers in production?
Attempts:
2 left
💡 Hint
Think about security and minimal exposure.
✗ Incorrect
Exposing only needed ports and controlling access improves security and reduces attack surface.