File size: 840 Bytes
8cc558e
 
 
 
2492fbe
 
 
 
 
 
e3a4f02
759c7e1
2492fbe
 
 
8cc558e
e3a4f02
 
 
 
 
 
8cc558e
 
2492fbe
 
8cc558e
 
d3623c5
8cc558e
e3a4f02
e257142
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
31
32
FROM python:3.11-slim

WORKDIR /app

# Create a non-root user and group
RUN groupadd -r appgroup && useradd -r -g appgroup -d /app -s /sbin/nologin -c "Docker image user" appuser

# Copy requirements file first to leverage Docker cache
COPY --chown=appuser:appgroup requirements.txt .

# Grant appuser ownership of /app
RUN chown appuser:appgroup /app

# Switch to the non-root user
USER appuser

# Create and activate virtual environment
RUN python -m venv .venv
ENV PATH="/app/.venv/bin:$PATH"

# Install dependencies using standard pip
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
# Ensure the appuser owns the application code as well
COPY --chown=appuser:appgroup server.py .

# Expose the port the server runs on
EXPOSE 7860

# Command to run the server with python directly
CMD ["python", "server.py"]