Update Dockerfile
Browse files- Dockerfile +14 -8
Dockerfile
CHANGED
|
@@ -1,23 +1,29 @@
|
|
| 1 |
-
# Use the official Python image from the Docker Hub
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
WORKDIR /code
|
| 5 |
|
|
|
|
| 6 |
COPY requirements.txt ./
|
| 7 |
-
|
| 8 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
|
|
|
| 12 |
USER user
|
| 13 |
|
| 14 |
-
|
| 15 |
-
PATH=/home/user/.local/bin:$PATH
|
| 16 |
-
|
| 17 |
WORKDIR $HOME/app
|
| 18 |
|
| 19 |
-
COPY --chown=user . $HOME/app/
|
| 20 |
-
|
| 21 |
# Expose the port that the FastAPI app will run on
|
| 22 |
EXPOSE 7860
|
| 23 |
|
|
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Create a user to avoid permission issues
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
|
| 6 |
+
# Set environment variables
|
| 7 |
+
ENV HOME=/home/user \
|
| 8 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 9 |
+
PYTHONUNBUFFERED=1
|
| 10 |
+
|
| 11 |
+
# Set the working directory in the container
|
| 12 |
WORKDIR /code
|
| 13 |
|
| 14 |
+
# Copy the requirements file and install dependencies
|
| 15 |
COPY requirements.txt ./
|
|
|
|
| 16 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 17 |
|
| 18 |
+
# Change ownership of the working directory to the user
|
| 19 |
+
COPY --chown=user . /code/
|
| 20 |
|
| 21 |
+
# Switch to the non-root user
|
| 22 |
USER user
|
| 23 |
|
| 24 |
+
# Set the working directory for the application
|
|
|
|
|
|
|
| 25 |
WORKDIR $HOME/app
|
| 26 |
|
|
|
|
|
|
|
| 27 |
# Expose the port that the FastAPI app will run on
|
| 28 |
EXPOSE 7860
|
| 29 |
|