0
0
Dockerdevops~20 mins

Port mapping with -p flag in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Port Mapping Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Understanding basic port mapping with Docker -p flag
What is the output when you run the command docker run -d -p 8080:80 nginx and then check the port mapping with docker port <container_id>?
A80/tcp -> 0.0.0.0:8080
B8080/tcp -> 127.0.0.1:80
C80/tcp -> 127.0.0.1:8080
D8080/tcp -> 0.0.0.0:80
Attempts:
2 left
💡 Hint
Remember the format is :.
🧠 Conceptual
intermediate
1:30remaining
Effect of omitting host IP in port mapping
When using docker run -p 127.0.0.1:8080:80 nginx, what is the difference compared to docker run -p 8080:80 nginx?
AThe container port 80 is accessible from any IP on the host network.
BThe container port 80 is only accessible from localhost (127.0.0.1) on the host.
CThe container port 80 is not accessible at all.
DThe container port 80 is mapped to port 127.0.0.1 on the container.
Attempts:
2 left
💡 Hint
Think about binding to a specific IP address on the host.
Troubleshoot
advanced
2:00remaining
Diagnosing port conflict error with Docker -p flag
You run docker run -p 80:80 nginx but get an error: Bind for 0.0.0.0:80 failed: port is already allocated. What is the most likely cause?
AAnother process on the host is already using port 80.
BThe container image does not expose port 80.
CDocker daemon is not running.
DThe container port 80 is blocked by firewall inside the container.
Attempts:
2 left
💡 Hint
Check what is using port 80 on your host machine.
🔀 Workflow
advanced
2:30remaining
Correct order to expose and map ports in Dockerfile and run command
Which is the correct order of steps to expose port 5000 in a Dockerfile and map it to host port 3000 when running the container?
A2,1,3,4
B3,1,2,4
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about building the image after editing the Dockerfile.
Best Practice
expert
2:30remaining
Choosing the safest port mapping for a public web app
You want to run a web app in Docker accessible from the internet on port 80, but avoid exposing the container port directly to all interfaces. Which command is the safest choice?
Adocker run -p 0.0.0.0:80:80 mywebapp
Bdocker run -p 127.0.0.1:80:80 mywebapp
Cdocker run -p 192.168.1.100:80:80 mywebapp
Ddocker run -p 80:80 mywebapp
Attempts:
2 left
💡 Hint
Consider binding to a specific public IP address of your host.