-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (43 loc) · 1.35 KB
/
Dockerfile
File metadata and controls
53 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Use Python 3.11 slim image
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
FLASK_APP=app.py \
FLASK_ENV=production \
PORT=5001
# Create and set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy only requirements first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies with minimal size
RUN pip install --no-cache-dir -r requirements.txt \
&& find /usr/local/lib/python3.11/site-packages -name "*.pyc" -delete \
&& find /usr/local/lib/python3.11/site-packages -name "__pycache__" -delete
# Copy application code
COPY . .
# Create non-root user for security
RUN adduser --disabled-password --gecos '' appuser \
&& chown -R appuser:appuser /app
USER appuser
# Expose port
EXPOSE ${PORT}
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT}/health || exit 1
# Start Gunicorn
CMD gunicorn --bind 0.0.0.0:${PORT} \
--workers=2 \
--threads=4 \
--worker-class=gthread \
--worker-tmp-dir /dev/shm \
--access-logfile - \
--error-logfile - \
app:app