EL GHAFRAOUI AYOUB commited on
Commit
8b0f095
·
1 Parent(s): 75d4ea8
Files changed (1) hide show
  1. Dockerfile +18 -15
Dockerfile CHANGED
@@ -1,27 +1,30 @@
1
  # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
4
- # Set working directory
5
- WORKDIR /app
6
 
7
- # Copy requirements first to leverage Docker cache
8
- COPY requirements.txt .
9
 
10
- # Install dependencies
11
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
12
 
13
- # Create a non-root user
14
- RUN useradd -m myuser
15
 
16
- # Create data directory with proper permissions
17
- RUN mkdir -p /app/data && \
18
- chown -R myuser:myuser /app/data
19
 
20
- # Switch to the non-root user
21
- USER myuser
22
 
23
- # Copy the rest of the application
24
- COPY . .
25
 
26
  # Expose port
27
  EXPOSE 8000
 
1
  # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
4
+ # Set up a new user named "user" with user ID 1000
5
+ RUN useradd -m -u 1000 user
6
 
7
+ # Switch to the "user" user
8
+ USER user
9
 
10
+ # Set home to the user's home directory
11
+ ENV HOME=/home/user \
12
+ PATH=/home/user/.local/bin:$PATH
13
+
14
+ # Set the working directory to the user's home directory
15
+ WORKDIR $HOME/app
16
 
17
+ # Copy requirements with correct ownership
18
+ COPY --chown=user requirements.txt .
19
 
20
+ # Install dependencies
21
+ RUN pip install --no-cache-dir -r requirements.txt
 
22
 
23
+ # Copy the application code with correct ownership
24
+ COPY --chown=user . .
25
 
26
+ # Create data directory in the persistent storage location
27
+ RUN mkdir -p /data
28
 
29
  # Expose port
30
  EXPOSE 8000