# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Builds ultralytics/ultralytics:latest-export image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
# Export-optimized derivative of ultralytics/ultralytics:latest for testing and benchmarks
# Includes export dependencies compatible with the GPU PyTorch stack

FROM ultralytics/ultralytics:latest

# Install export dependencies
# Numpy 1.26.4 required for TensorFlow export compatibility
# Albumentations re-resolves the base image's pydantic against LiteRT's typing-extensions<4.13 cap (via xdsl)
# Note tensorrt installed on-demand as depends on runtime environment CUDA version
RUN uv pip install --system --no-cache -e ".[export]" \
    "onnxruntime-gpu[cuda]" paddlepaddle x2paddle albumentations numpy==1.26.4 && \
    rm -rf tmp ~/.cache /root/.config/Ultralytics/persistent_cache.json

# Usage --------------------------------------------------------------------------------------------------------------

# Production builds: https://github.com/ultralytics/ultralytics/blob/main/.github/workflows/docker.yml
# Example (build): t=ultralytics/ultralytics:latest-export && docker build -f docker/Dockerfile-export -t $t .
# Example (push): docker push $t
# Example (pull): t=ultralytics/ultralytics:latest-export && docker pull $t
# Example (run): docker run -it --ipc=host --device nvidia.com/gpu=all $t
# Example (run-with-volume): docker run -it --ipc=host --device nvidia.com/gpu=all -v "$PWD/shared/datasets:/datasets" $t
# CDI requires Docker >= 28.2.0 and nvidia-container-toolkit >= 1.18.
# Legacy --gpus all can lose GPU access after host systemd daemon reloads (nvidia-container-toolkit#48).
