amaye15 commited on
Commit
b138bfa
·
1 Parent(s): 517c4f8
Files changed (1) hide show
  1. Dockerfile +10 -19
Dockerfile CHANGED
@@ -1,42 +1,33 @@
1
  # Dockerfile
2
 
3
- # 1. Choose a base Python image
4
- # Using a specific version is recommended for reproducibility.
5
- # The '-slim' variant is smaller.
6
- FROM python:3.12-slim
7
 
8
- # 2. Set environment variables (optional but good practice)
9
- ENV PYTHONDONTWRITEBYTECODE 1
10
- ENV PYTHONUNBUFFERED 1
11
 
12
  # Create a non-root user and group
13
  ARG UID=1000
14
  ARG GID=1000
15
  RUN groupadd -g ${GID} --system appgroup && useradd -u ${UID} -g appgroup --system appuser
16
 
17
-
18
- # 3. Set the working directory inside the container
19
  WORKDIR /app
20
 
21
  # Create data directory and set permissions
22
  RUN mkdir /app/data && chown appuser:appgroup /app/data
23
 
24
- # 4. Copy only the requirements file first to leverage Docker cache
25
  COPY requirements.txt .
26
-
27
- # 5. Install dependencies
28
- # --no-cache-dir makes the image smaller
29
- # --upgrade pip ensures we have the latest pip
30
  RUN pip install --no-cache-dir --upgrade pip && \
31
  pip install --no-cache-dir -r requirements.txt
32
 
33
- # 6. Copy the rest of the application code into the working directory
34
  COPY . .
 
 
 
 
35
 
36
- # 7. Expose the port the app runs on (uvicorn default is 8000)
37
  EXPOSE 8000
38
 
39
- # 8. Define the default command to run when the container starts
40
- # Use exec form for proper signal handling.
41
- # Do NOT use --reload in production.
42
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
  # Dockerfile
2
 
3
+ FROM python:3.10-slim
 
 
 
4
 
5
+ ENV PYTHONDONTWRITEBYTECODE 1
6
+ ENV PYTHONUNBUFFERED 1
 
7
 
8
  # Create a non-root user and group
9
  ARG UID=1000
10
  ARG GID=1000
11
  RUN groupadd -g ${GID} --system appgroup && useradd -u ${UID} -g appgroup --system appuser
12
 
 
 
13
  WORKDIR /app
14
 
15
  # Create data directory and set permissions
16
  RUN mkdir /app/data && chown appuser:appgroup /app/data
17
 
18
+ # Copy requirements and install as root first (some packages might need it)
19
  COPY requirements.txt .
 
 
 
 
20
  RUN pip install --no-cache-dir --upgrade pip && \
21
  pip install --no-cache-dir -r requirements.txt
22
 
23
+ # Copy application code and set permissions
24
  COPY . .
25
+ RUN chown -R appuser:appgroup /app
26
+
27
+ # Switch to the non-root user
28
+ USER appuser
29
 
 
30
  EXPOSE 8000
31
 
32
+ # Run uvicorn as the non-root user
 
 
33
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]