Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +19 -10
Dockerfile
CHANGED
|
@@ -2,22 +2,31 @@
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
| 5 |
-
ENV PYTHONDONTWRITEBYTECODE
|
| 6 |
-
ENV PYTHONUNBUFFERED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Set the working directory in the container
|
| 9 |
-
WORKDIR /
|
| 10 |
|
| 11 |
-
# Copy
|
| 12 |
-
COPY . /
|
| 13 |
|
| 14 |
# Install any needed packages specified in requirements.txt
|
| 15 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Run the application
|
| 21 |
-
|
| 22 |
-
# Note: In a production environment, you would use a production-ready server like Gunicorn or uWSGI
|
| 23 |
-
CMD ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]
|
|
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
# Create a non-root user
|
| 9 |
+
RUN useradd -m -u 1000 appuser && \
|
| 10 |
+
mkdir -p /app && \
|
| 11 |
+
chown -R appuser:appuser /app
|
| 12 |
|
| 13 |
# Set the working directory in the container
|
| 14 |
+
WORKDIR /app
|
| 15 |
|
| 16 |
+
# Copy requirements first (for better caching)
|
| 17 |
+
COPY --chown=appuser:appuser requirements.txt /app/
|
| 18 |
|
| 19 |
# Install any needed packages specified in requirements.txt
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
+
# Copy the entire project
|
| 23 |
+
COPY --chown=appuser:appuser . /app/
|
| 24 |
+
|
| 25 |
+
# Switch to non-root user
|
| 26 |
+
USER appuser
|
| 27 |
+
|
| 28 |
+
# Expose port 7860
|
| 29 |
+
EXPOSE 7860
|
| 30 |
|
| 31 |
# Run the application
|
| 32 |
+
CMD ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:7860"]
|
|
|
|
|
|