codeBOKER commited on
Commit
d1309f7
·
verified ·
1 Parent(s): 6c7f43b

Create Dockerfile

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