-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
100 lines (85 loc) · 2.7 KB
/
Copy pathDockerfile
File metadata and controls
100 lines (85 loc) · 2.7 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Use multi-stage build for smaller final image
FROM ubuntu:23.10 AS builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH" \
# Add environment variables for better PyTorch performance
OMP_NUM_THREADS=4 \
MKL_NUM_THREADS=4 \
NUMEXPR_NUM_THREADS=4 \
CUDA_LAUNCH_BLOCKING=1
# Install system dependencies and security updates
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
build-essential \
gcc \
python3.11-dev \
python3-dev \
python3.11-venv \
python3-pip \
wget \
git \
poppler-utils \
# Add dependencies for PDF and image processing
libpoppler-dev \
libpoppler-cpp-dev \
pkg-config \
# Add dependencies for PyTorch
libgl1 \
libglib2.0-0 \
# Cleanup apt cache
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python3.11 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt
# Final stage
FROM ubuntu:23.10
ENV PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH" \
# Add environment variables for better PyTorch performance
OMP_NUM_THREADS=4 \
MKL_NUM_THREADS=4 \
NUMEXPR_NUM_THREADS=4 \
CUDA_LAUNCH_BLOCKING=1 \
# Add environment variables for memory management
PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512
# Create non-root user
RUN groupadd -r datafoguser && useradd -r -g datafoguser -s /sbin/nologin -d /home/datafoguser datafoguser
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
poppler-utils \
libpoppler-cpp-dev \
libgl1 \
libglib2.0-0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
# Create and set permissions for required directories
RUN mkdir -p /tmp /home/datafoguser/tmp /home/datafoguser/app && \
chown -R datafoguser:datafoguser /home/datafoguser && \
chmod 755 /home/datafoguser && \
chmod 1777 /tmp /home/datafoguser/tmp
# Copy application code
COPY --chown=datafoguser:datafoguser app /home/datafoguser/app
# Set working directory
WORKDIR /home/datafoguser/app
# Switch to non-root user
USER datafoguser
# Expose port
EXPOSE 8000
# Set entrypoint script
COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]