File size: 902 Bytes
3973360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
# Use the slim variant of Python 3.11 to reduce the size
FROM python:3.11-slim

# Add a non-root user for better security
RUN useradd -m -u 1000 user

# Switch to non-root user
USER user

# Ensure pip, setuptools, and wheel are up to date
RUN python -m pip install --upgrade pip setuptools wheel

# Set PATH to include user installs
ENV PATH="/home/user/.local/bin:$PATH"

# Set the working directory inside the container
WORKDIR /app

# Copy requirements.txt file and install dependencies
COPY --chown=user ./requirements.txt /app/requirements.txt

# Install only necessary dependencies from the requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

# Copy the rest of the application code to the working directory
COPY --chown=user . /app

# Start the FastAPI application with uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]