Bird
0
0

What is the effect of running docker run -p 8080:5000 flask-app for a Flask container exposing port 5000?

medium📝 component behavior Q5 of 15
Flask - Deployment
What is the effect of running docker run -p 8080:5000 flask-app for a Flask container exposing port 5000?
AMaps host port 8080 to container port 5000, making app accessible on localhost:8080
BMaps container port 8080 to host port 5000, making app accessible on localhost:5000
CRuns container without port mapping, app inaccessible externally
DCauses an error because ports must be the same
Step-by-Step Solution
Solution:
  1. Step 1: Understand docker run -p syntax

    The syntax -p hostPort:containerPort maps a port on the host machine to a port inside the container.
  2. Step 2: Apply to given ports

    Here, host port 8080 maps to container port 5000, so accessing localhost:8080 on host forwards to Flask app inside container on port 5000.
  3. Final Answer:

    Maps host port 8080 to container port 5000, making app accessible on localhost:8080 -> Option A
  4. Quick Check:

    docker run -p host:container maps ports correctly [OK]
Quick Trick: Use -p hostPort:containerPort to expose container ports [OK]
Common Mistakes:
MISTAKES
  • Reversing host and container ports in -p option
  • Assuming ports must be identical
  • Not mapping ports and expecting external access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes