-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
31 lines (23 loc) · 956 Bytes
/
Copy pathDockerfile
File metadata and controls
31 lines (23 loc) · 956 Bytes
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
FROM python:3.11-slim
# Security & runtime env.
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app
# Install dependencies first for better layer caching.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application source.
COPY . .
# Run as a non-root user (defence in depth — a compromised process is not root).
RUN useradd --create-home --uid 10001 appuser \
&& mkdir -p /app/logs \
&& chown -R appuser:appuser /app
USER appuser
EXPOSE 4000
# Container-level liveness check hitting the app's /health endpoint.
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD python -c "import urllib.request,sys; \
sys.exit(0) if urllib.request.urlopen('http://127.0.0.1:4000/health').status==200 else sys.exit(1)"
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "4000", "--workers", "2"]