0
0
Flaskframework~20 mins

Docker containerization in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Mastery for Flask
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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"]
AThe Flask app starts and is accessible on port 5000 inside the container.
BThe container fails to start because the CMD syntax is incorrect.
CThe Flask app starts but is only accessible on localhost inside the container, not from outside.
DThe container starts but Flask raises an error because FLASK_APP is not set.
Attempts:
2 left
💡 Hint
Think about how Flask's default port and host settings work inside Docker.
📝 Syntax
intermediate
1: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?
ACOPY /root/*.py /app/
BCOPY /app/*.py /app/
CCOPY ./*.py /app/
DCOPY *.py /app/
Attempts:
2 left
💡 Hint
Remember COPY paths are relative to the build context.
🔧 Debug
advanced
2: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
ABecause 'localhost' inside the container points to the container itself, not the host machine.
BBecause the database URL is missing the port number.
CBecause Flask cannot connect to databases inside Docker containers.
DBecause the database URL must use '127.0.0.1' instead of 'localhost'.
Attempts:
2 left
💡 Hint
Think about network isolation in Docker containers.
state_output
advanced
2: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"
AThe container crashes because volumes cannot be used with Flask apps.
BCode changes on the host immediately reflect inside the container without rebuilding.
CCode changes require rebuilding the image to take effect inside the container.
DThe container ignores the volume and uses the image code only.
Attempts:
2 left
💡 Hint
Volumes link host files to container files in real time.
🧠 Conceptual
expert
3: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?
ATo allow running multiple Flask apps in one container.
BTo enable Flask apps to automatically restart on code changes.
CTo reduce the final image size by separating build dependencies from runtime environment.
DTo make the container run faster by using multiple CPU cores.
Attempts:
2 left
💡 Hint
Think about what stays in the final image after building.