-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
47 lines (34 loc) · 1.15 KB
/
Dockerfile
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
FROM python:3.9-slim
# Set default values for PUID and PGID
ENV PUID=1000 \
PGID=1000
# Create a non-root user to run the application with customizable UID/GID
RUN groupadd -r -g ${PGID} appuser && \
useradd -r -u ${PUID} -g appuser appuser
WORKDIR /app
# Install curl for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
FLASK_APP=app.py
# Copy application files
COPY --chown=appuser:appuser . .
# Create necessary directories with proper permissions
RUN chown -R appuser:appuser /app && \
chmod -R 755 /app
# Clean up
RUN rm -f /app/userdata/*
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:${PORT:-5001}/ || exit 1
# Expose the port the app runs on
EXPOSE ${PORT:-5001}
# Command to run the application with Flask's development server
CMD ["python", "app.py"]