File size: 1,058 Bytes
31859b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

FROM python:3.9-slim

# 2. Set the working directory inside the container
# This is where our application code will live.
WORKDIR /code

# 3. Copy the requirements file into the container at /code
# We copy this first to leverage Docker's layer caching.
# If requirements.txt doesn't change, Docker won't reinstall dependencies on subsequent builds.
COPY ./requirements.txt /code/requirements.txt

# 4. Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# 5. Copy the rest of the application's code into the container at /code
COPY ./app.py /code/app.py

# 6. Expose the port the app runs on
# FastAPI with Uvicorn defaults to port 8000.
EXPOSE 8000

# 7. Define the command to run the application
# This command starts the Uvicorn server.
# --host 0.0.0.0 makes the server accessible from outside the container.
# --port 8000 matches the exposed port.
# app:app refers to the 'app' object inside the 'app.py' file.
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]