-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
39 lines (28 loc) · 1.16 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
# Use the official Python 3.12 slim image as the base
FROM python:3.12-slim
# Set environment variables to prevent Python from writing .pyc files and to ensure output is flushed
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Set the working directory inside the container
WORKDIR /app
# Install system dependencies required for building Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy only the requirements file to leverage Docker cache
COPY requirements.txt /app/
# Upgrade pip and install Python dependencies globally
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code into the container
COPY . /app
# Create a non-root user for better security
RUN useradd -m appuser
# Change ownership of the /app directory to appuser
RUN chown -R appuser:appuser /app
# Switch to the non-root user
USER appuser
# Expose port 8080 for Cloud Run (or any other target environment)
EXPOSE 8080
# Command to run the application with Uvicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]