0
0
Dockerdevops~20 mins

Exposing ports to host in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Port Exposure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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?
AStarts an nginx container with port 80 inside mapped to port 80 on the host.
BStarts an nginx container with port 8080 inside mapped to port 80 on the host.
CStarts an nginx container with port 80 inside mapped to port 8080 on the host.
DStarts an nginx container with port 8080 inside mapped to port 8080 on the host.
Attempts:
2 left
💡 Hint
The format is -p hostPort:containerPort.
🧠 Conceptual
intermediate
1:30remaining
Why expose ports in Docker containers?
Why do we expose ports from a Docker container to the host machine?
ATo allow network traffic from the host to reach services inside the container.
BTo increase the container's CPU usage.
CTo make the container use more memory.
DTo stop the container from running.
Attempts:
2 left
💡 Hint
Think about how you access a website running inside a container.
Configuration
advanced
2: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:
A- "3000"
B- "5000:3000"
C- "5000"
D- "3000:5000"
Attempts:
2 left
💡 Hint
Remember the format is hostPort:containerPort.
Troubleshoot
advanced
2: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?
AThe container's service is not listening on port 80 inside the container.
BThe host port 8080 is blocked by firewall.
CDocker daemon is not running.
DThe container image is missing.
Attempts:
2 left
💡 Hint
Check if the service inside the container is running on the expected port.
Best Practice
expert
3: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?
AExpose ports randomly to confuse attackers.
BExpose only necessary ports and use firewall rules to restrict access.
CDo not expose any ports and rely on container internal networking only.
DExpose all container ports to the host for easy access.
Attempts:
2 left
💡 Hint
Think about security and minimal exposure.