Update Dockerfile
Browse files- Dockerfile +10 -7
Dockerfile
CHANGED
|
@@ -1,26 +1,29 @@
|
|
| 1 |
# Use the official lightweight Python image.
|
| 2 |
-
# https://hub.docker.com/_/python
|
| 3 |
FROM python:3.9-slim
|
| 4 |
|
| 5 |
# Set the working directory to /app
|
| 6 |
WORKDIR /app
|
| 7 |
|
| 8 |
-
# Create a non-root user with an explicit UID
|
| 9 |
-
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
|
| 10 |
RUN adduser -u 1000 --disabled-password --gecos "" appuser && chown -R appuser /app
|
| 11 |
USER appuser
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
| 14 |
COPY --chown=appuser requirements.txt .
|
| 15 |
|
| 16 |
# Install the dependencies
|
|
|
|
| 17 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 18 |
|
| 19 |
# Copy the rest of the application code
|
| 20 |
COPY --chown=appuser . .
|
| 21 |
|
| 22 |
-
# Expose the port
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
# Command to run the application
|
| 26 |
-
|
|
|
|
|
|
| 1 |
# Use the official lightweight Python image.
|
|
|
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Set the working directory to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Create a non-root user with an explicit UID
|
|
|
|
| 8 |
RUN adduser -u 1000 --disabled-password --gecos "" appuser && chown -R appuser /app
|
| 9 |
USER appuser
|
| 10 |
|
| 11 |
+
# CRITICAL FIX: Add the user's local bin directory to PATH so the shell can find 'uvicorn'
|
| 12 |
+
ENV PATH="/home/appuser/.local/bin:$PATH"
|
| 13 |
+
|
| 14 |
+
# Copy the requirements file
|
| 15 |
COPY --chown=appuser requirements.txt .
|
| 16 |
|
| 17 |
# Install the dependencies
|
| 18 |
+
# Note: As a non-root user, pip will default to --user install, putting files in ~/.local
|
| 19 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 20 |
|
| 21 |
# Copy the rest of the application code
|
| 22 |
COPY --chown=appuser . .
|
| 23 |
|
| 24 |
+
# Expose the port
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
+
# Command to run the application
|
| 28 |
+
# Using 'python -m uvicorn' is safer than just 'uvicorn' to ensure it uses the installed module
|
| 29 |
+
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|