NitinBot001 commited on
Commit
3f08411
·
verified ·
1 Parent(s): c682766

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -10
Dockerfile CHANGED
@@ -2,22 +2,31 @@
2
  FROM python:3.11-slim
3
 
4
  # Set environment variables
5
- ENV PYTHONDONTWRITEBYTECODE 1
6
- ENV PYTHONUNBUFFERED 1
 
 
 
 
 
7
 
8
  # Set the working directory in the container
9
- WORKDIR /usr/src/app
10
 
11
- # Copy the current directory contents into the container at /usr/src/app
12
- COPY . /usr/src/app/
13
 
14
  # Install any needed packages specified in requirements.txt
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
- # Expose port 8000 for the Django development server
18
- EXPOSE 8000
 
 
 
 
 
 
19
 
20
  # Run the application
21
- # Use the entrypoint to run migrations and then start the server
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"]