Samfy001 commited on
Commit
f5a2aaa
·
verified ·
1 Parent(s): 538d586

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -6
Dockerfile CHANGED
@@ -6,31 +6,39 @@ WORKDIR /app
6
  # Set environment variables
7
  ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV PYTHONUNBUFFERED=1
 
9
 
10
  # Install system dependencies
11
  RUN apt-get update && apt-get install -y \
12
  gcc \
 
13
  && rm -rf /var/lib/apt/lists/*
14
 
 
 
 
15
  # Copy requirements first for better caching
16
  COPY requirements.txt .
17
 
18
  # Install Python dependencies
19
- RUN pip install --no-cache-dir -r requirements.txt
 
20
 
21
  # Copy application code
22
  COPY main.py .
23
 
24
- # Create non-root user
25
- RUN useradd --create-home --shell /bin/bash app
 
 
26
  USER app
27
 
28
  # Expose port
29
  EXPOSE 8000
30
 
31
  # Health check
32
- HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
33
- CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
34
 
35
  # Run the application
36
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
6
  # Set environment variables
7
  ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV PYTHONUNBUFFERED=1
9
+ ENV PYTHONPATH=/app
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y \
13
  gcc \
14
+ curl \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # Create non-root user early
18
+ RUN useradd --create-home --shell /bin/bash --uid 1000 app
19
+
20
  # Copy requirements first for better caching
21
  COPY requirements.txt .
22
 
23
  # Install Python dependencies
24
+ RUN pip install --no-cache-dir --upgrade pip && \
25
+ pip install --no-cache-dir -r requirements.txt
26
 
27
  # Copy application code
28
  COPY main.py .
29
 
30
+ # Change ownership of the app directory
31
+ RUN chown -R app:app /app
32
+
33
+ # Switch to non-root user
34
  USER app
35
 
36
  # Expose port
37
  EXPOSE 8000
38
 
39
  # Health check
40
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
41
+ CMD curl -f http://localhost:8000/health || exit 1
42
 
43
  # Run the application
44
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]