ultralytics/docker/Dockerfile-python

52 lines
2.2 KiB
Text
Raw Normal View History

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# Builds ultralytics/ultralytics:latest-python image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
# Lightweight CPU image optimized for YOLO inference
2023-07-18 15:11:13 +00:00
# Use official Python base image for reproducibility (3.11.10 for export and 3.12.10 for inference)
2024-09-28 23:02:35 +00:00
FROM python:3.11.10-slim-bookworm
2023-07-18 15:11:13 +00:00
# Set environment variables (suppress PyTorch NNPACK warnings)
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_BREAK_SYSTEM_PACKAGES=1 \
UV_BREAK_SYSTEM_PACKAGES=1 \
TORCH_CPP_LOG_LEVEL=ERROR
2023-07-18 15:11:13 +00:00
# Downloads to user config dir
ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \
https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \
/root/.config/Ultralytics/
2023-07-18 15:11:13 +00:00
# Install linux packages
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3-pip git zip unzip wget curl htop libgl1 libglib2.0-0 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
2023-07-18 15:11:13 +00:00
# Create working directory
WORKDIR /ultralytics
2023-07-18 15:11:13 +00:00
# Copy contents and configure git
COPY . .
RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \
sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml
ADD https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt .
2023-07-18 15:11:13 +00:00
# Install pip packages
RUN pip install uv && \
uv pip install --system -e . --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match && \
# Remove extra build files
rm -rf tmp ~/.cache /root/.config/Ultralytics/persistent_cache.json
2026-01-02 02:29:19 +00:00
# Usage --------------------------------------------------------------------------------------------------------------
# Production builds: https://github.com/ultralytics/ultralytics/blob/main/.github/workflows/docker.yml
# Example (build): t=ultralytics/ultralytics:latest-python && docker build -f docker/Dockerfile-python -t $t .
# Example (push): docker push $t
# Example (pull): t=ultralytics/ultralytics:latest-python && docker pull $t
# Example (run): docker run -it --ipc=host $t
# Example (run-with-volume): docker run -it --ipc=host -v "$PWD/shared/datasets:/datasets" $t