Bird
0
0

Given this Dockerfile snippet:

medium📝 component behavior Q4 of 15
Flask - Deployment
Given this Dockerfile snippet:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["flask", "run", "--host=0.0.0.0"]

What happens when you run the container?
AContainer fails because requirements.txt is missing
BFlask app runs but listens only on localhost inside the container
CFlask app runs but port 5000 is not accessible outside the container
DFlask app runs and listens on all network interfaces at port 5000
Step-by-Step Solution
Solution:
  1. Step 1: Analyze CMD and EXPOSE instructions

    The CMD runs Flask with --host=0.0.0.0, making it listen on all interfaces. EXPOSE 5000 declares port 5000 for external access.
  2. Step 2: Understand container networking

    Because Flask listens on 0.0.0.0 and port 5000 is exposed, the app is accessible from outside the container on port 5000.
  3. Final Answer:

    Flask app runs and listens on all network interfaces at port 5000 -> Option D
  4. Quick Check:

    CMD host=0.0.0.0 + EXPOSE 5000 = accessible app [OK]
Quick Trick: Use --host=0.0.0.0 to expose Flask outside container [OK]
Common Mistakes:
MISTAKES
  • Assuming Flask listens only on localhost by default
  • Thinking EXPOSE opens ports automatically without CMD
  • Confusing container internal ports with host ports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes