QuizzesDockerizing FastAPI — Images Done Right — Concept Check
intermediate
fastapi

Dockerizing FastAPI — Images Done Right — Concept Check

Questions on Dockerizing FastAPI — Images Done Right. A slim Python base, requirements installed before code (layer-cache order), a non-root user, and uvicorn as CMD — plus docker-compose wiring Postgres/Redis for a one-command dev environment.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Dockerizing FastAPI — Images Done Right — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You notice that rebuilding your Docker image takes longer than expected after code changes. What might be causing this?

    • AUsing a full Python base image instead of slim
    • BCOPY requirements.txt after copying source code
    • CRunning pip install without --no-cache-dir
    • DNot using a non-root user for the container
  2. 2.A developer uses alpine as the base image for their FastAPI Dockerfile and encounters issues with certain Python packages. What is the likely cause?

    • AThe Dockerfile is missing the EXPOSE instruction
    • BThe base image is missing Python entirely
    • CAlpine uses musl instead of glibc, breaking compiled wheels
    • DAlpine is too large, causing build failures
  3. 3.Why is it important to declare a non-root user in a Dockerfile?

    • ATo ensure the application logs are flushed immediately
    • BTo reduce the size of the Docker image
    • CTo improve the performance of the application
    • DTo prevent container escape vulnerabilities
  4. 4.After deploying your FastAPI app using docker-compose, you notice the app starts before Postgres is ready. What could resolve this issue?

    • ARemove the EXPOSE instruction from the Dockerfile
    • BIncrease the number of workers in uvicorn
    • CAdd a healthcheck condition to Postgres in docker-compose
    • DUse a full Python base image instead of slim
  5. 5.What is a key benefit of using the exec-form CMD in a Dockerfile?

    • AIt automatically handles environment variables
    • BIt allows for faster image builds
    • CIt ensures SIGTERM signals reach the application for graceful shutdown
    • DIt reduces the size of the Docker image
  6. 6.A developer claims that using a full Python base image is better for production due to more tools. Why might this be incorrect?

    • ASlim images lack necessary Python libraries
    • BFull images are larger, leading to slower deployments
    • CSlim images cannot run FastAPI applications
    • DFull images automatically configure security settings
  7. 7.In docker-compose, why should the same image be used across different environments?

    • ATo ensure consistent application behavior across environments
    • BTo allow for different environment-specific configurations
    • CTo minimize the size of the Docker image
    • DTo reduce the number of required environment variables
  8. 8.What is the purpose of setting PYTHONDONTWRITEBYTECODE in the Dockerfile?

    • ATo ensure the application runs as a non-root user
    • BTo allow for faster image builds
    • CTo prevent .pyc files from being generated
    • DTo ensure logs are flushed immediately