Challenge - 5 Problems
Docker Mastery for Flask
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when you run this Dockerfile for a Flask app?
Consider this Dockerfile for a simple Flask app. What will be the output when you run the container and access the root URL?
Flask
FROM python:3.12-slim WORKDIR /app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . ./ ENV FLASK_APP=app.py CMD ["flask", "run", "--host=0.0.0.0"]
Attempts:
2 left
💡 Hint
Think about how Flask's default port and host settings work inside Docker.
✗ Incorrect
The Dockerfile sets FLASK_APP and runs Flask with --host=0.0.0.0, making the app listen on all interfaces inside the container, typically port 5000.
📝 Syntax
intermediate1:30remaining
Which Dockerfile command correctly copies only Python files to /app?
You want to copy only .py files from your project root to /app in the container. Which COPY command is correct?
Attempts:
2 left
💡 Hint
Remember COPY paths are relative to the build context.
✗ Incorrect
COPY *.py /app/ copies all Python files from the build context root to /app in the container.
🔧 Debug
advanced2:30remaining
Why does this Flask app inside Docker fail to connect to the database?
You have a Flask app in Docker that connects to a database at 'localhost:5432'. The app fails to connect. Why?
Flask
DATABASE_URL = 'postgresql://user:pass@localhost:5432/dbname' app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URL
Attempts:
2 left
💡 Hint
Think about network isolation in Docker containers.
✗ Incorrect
'localhost' inside a container refers to the container itself, so it cannot reach services running on the host machine.
❓ state_output
advanced2:30remaining
What is the effect of this Docker Compose service configuration on Flask app state?
Given this docker-compose.yml snippet, what happens to the Flask app's code changes on the host during container runtime?
Flask
services:
web:
build: .
volumes:
- .:/app
ports:
- "5000:5000"Attempts:
2 left
💡 Hint
Volumes link host files to container files in real time.
✗ Incorrect
The volume mounts the current directory into /app inside the container, so changes on the host appear immediately inside the container.
🧠 Conceptual
expert3:00remaining
Why use multi-stage builds in Docker for Flask apps?
What is the main benefit of using multi-stage Docker builds when containerizing a Flask application?
Attempts:
2 left
💡 Hint
Think about what stays in the final image after building.
✗ Incorrect
Multi-stage builds let you install build tools and dependencies in one stage, then copy only the needed files to a smaller final image.