Dockerfile
1.24 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
# Use Python 3.9 slim image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements-docker.txt .
# Install Python dependencies
# 使用国内镜像 + PyTorch官方CPU wheel链接,确保不安装CUDA版本
RUN pip install --no-cache-dir -r requirements-docker.txt \
-i https://mirrors.aliyun.com/pypi/simple/ \
--trusted-host mirrors.aliyun.com \
--retries 5 \
--timeout 300
# Copy application code
COPY . .
# Create necessary directories with proper permissions
RUN mkdir -p \
data/uploads \
data/design_images \
data/logs \
data/faiss \
&& chmod -R 755 data
# Create non-root user for security
RUN useradd -m -u 1000 appuser && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 5088
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5088/health || exit 1
# Run the application
CMD ["python", "app.py"]