0
0
FastAPIframework~10 mins

Docker containerization in FastAPI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the base image for a FastAPI Docker container.

FastAPI
FROM [1]
Drag options to blanks, or click blank then click option'
Aalpine:latest
Bnode:latest
Cubuntu:20.04
Dpython:3.12-slim
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a Node.js or Ubuntu base image which is not optimized for Python FastAPI.
2fill in blank
medium

Complete the code to copy the application files into the Docker image.

FastAPI
COPY [1] /app
Drag options to blanks, or click blank then click option'
ADockerfile
Brequirements.txt
C.
Dmain.py
Attempts:
3 left
💡 Hint
Common Mistakes
Copying only one file like main.py or requirements.txt, missing other files.
3fill in blank
hard

Fix the error in the command to install dependencies inside the Dockerfile.

FastAPI
RUN pip install [1] -r requirements.txt
Drag options to blanks, or click blank then click option'
A--requirement
B--install
C--upgrade
D--require
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid flags like --install or --require which cause errors.
4fill in blank
hard

Fill both blanks to expose the correct port and run the FastAPI app with uvicorn.

FastAPI
EXPOSE [1]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "[2]"]
Drag options to blanks, or click blank then click option'
A8000
B8080
C5000
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using different ports for expose and run causing connection issues.
5fill in blank
hard

Fill all three blanks to create a Dockerfile snippet that sets the working directory, copies files, and installs dependencies.

FastAPI
WORKDIR [1]
COPY [2] .
RUN pip install -r [3]
Drag options to blanks, or click blank then click option'
A/app
B.
Crequirements.txt
D/src
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong working directory or copying wrong files or missing requirements.txt.