Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (47 loc) · 1.37 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (47 loc) · 1.37 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
54
55
56
57
# Base image
FROM python:3.12-slim
# Environment settings
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
FLASK_ENV=production \
FLASK_DEBUG=0
# Working directory
WORKDIR /app
# Install temporary build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*
# Python dependencies first for better layer caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --upgrade pip setuptools wheel \
&& pip install -r requirements.txt \
&& pip install gunicorn \
&& apt-get purge -y --auto-remove build-essential gcc \
&& rm -rf /root/.cache/pip
# Application files
COPY . .
# Create non-root user and fix permissions
RUN useradd --create-home --shell /bin/bash appuser \
&& chown -R appuser:appuser /app
# Use non-root user
USER appuser
# Runtime port inside the container
EXPOSE 5000
# Start Flask app with Gunicorn
CMD ["gunicorn", "app:app", \
"--bind", "0.0.0.0:5000", \
"--workers", "2", \
"--worker-class", "gthread", \
"--threads", "4", \
"--timeout", "180", \
"--graceful-timeout", "30", \
"--keep-alive", "5", \
"--max-requests", "300", \
"--max-requests-jitter", "30", \
"--access-logfile", "-", \
"--error-logfile", "-"]