-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
164 lines (131 loc) · 4.59 KB
/
Dockerfile
File metadata and controls
164 lines (131 loc) · 4.59 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# =============================================================================
# YOLOv8 Product Detection - Docker Image
# =============================================================================
# Production-ready container for training and inference
#
# Build:
# docker build -t yolov8-product-detection .
#
# Run training:
# docker run --gpus all -v $(pwd)/data:/app/data \
# -v $(pwd)/runs:/app/runs \
# yolov8-product-detection python src/train.py
#
# Run inference:
# docker run --gpus all -v $(pwd)/images:/app/images \
# -v $(pwd)/output:/app/output \
# yolov8-product-detection python src/inference.py --source /app/images
#
# =============================================================================
# -----------------------------------------------------------------------------
# Base Image - CUDA-enabled Python
# -----------------------------------------------------------------------------
FROM python:3.10-slim AS base
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
wget \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# -----------------------------------------------------------------------------
# Builder Stage - Install Python dependencies
# -----------------------------------------------------------------------------
FROM base AS builder
WORKDIR /app
# Copy requirements first for caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Download YOLOv8 pretrained weights
RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')"
# -----------------------------------------------------------------------------
# Production Image
# -----------------------------------------------------------------------------
FROM base AS production
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy pretrained weights
COPY --from=builder /root/.cache/torch /root/.cache/torch
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p data runs output logs
# Set default command
CMD ["python", "-c", "print('YOLOv8 Product Detection Container Ready!')"]
# -----------------------------------------------------------------------------
# GPU-enabled Image (requires NVIDIA Container Toolkit)
# -----------------------------------------------------------------------------
FROM nvidia/cuda:11.8-cudnn8-runtime-ubuntu22.04 AS gpu
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive
# Install Python and system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.10 \
python3-pip \
python3.10-dev \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
wget \
curl \
git \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/bin/python3.10 /usr/bin/python \
&& ln -sf /usr/bin/pip3 /usr/bin/pip
WORKDIR /app
# Copy requirements
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# Download YOLOv8 pretrained weights
RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')"
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p data runs output logs
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "from ultralytics import YOLO; print('OK')" || exit 1
# Default command
CMD ["python", "-c", "print('YOLOv8 Product Detection GPU Container Ready!')"]
# -----------------------------------------------------------------------------
# Development Image
# -----------------------------------------------------------------------------
FROM production AS development
# Install dev dependencies
RUN pip install --no-cache-dir \
pytest \
pytest-cov \
black \
flake8 \
isort \
mypy \
jupyter \
jupyterlab
# Expose Jupyter port
EXPOSE 8888
# Default command for development
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--allow-root", "--no-browser"]