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"]