Skip to content

Commit ebc5c89

Browse files
authored
Update Dockerfile
1 parent d293cdf commit ebc5c89

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

backend/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Use Python 3.12.1 for smaller image size
2+
FROM python:3.12.1
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
ENV PYTHONUNBUFFERED=1
7+
8+
# Set work directory
9+
WORKDIR /app
10+
11+
# Install system dependencies (if needed)
12+
RUN apt-get update && apt-get install -y \
13+
gcc \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Copy requirements first (for better Docker layer caching)
17+
COPY requirements.txt .
18+
19+
# Install Python dependencies
20+
RUN pip install --no-cache-dir --upgrade pip
21+
RUN pip install --no-cache-dir -r requirements.txt
22+
23+
# Copy application code (secrets excluded by .dockerignore)
24+
COPY . .
25+
26+
# Create non-root user for security
27+
RUN adduser --disabled-password --gecos '' appuser
28+
RUN chown -R appuser:appuser /app
29+
USER appuser
30+
31+
# Expose port
32+
EXPOSE 8000
33+
34+
# Health check (optional)
35+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
36+
CMD curl -f http://localhost:8000/docs || exit 1
37+
38+
# Command to run FastAPI with uvicorn
39+
# Adjust the module:app part based on your file structure:
40+
# If your FastAPI app is in main.py: uvicorn main:app
41+
# If your FastAPI app is in app.py: uvicorn app:app
42+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)