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

# Builds ultralytics/ultralytics:latest-conda image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
# Image is optimized for Ultralytics Anaconda (https://anaconda.org/conda-forge/ultralytics) installation and usage

# Start FROM miniconda3 image https://hub.docker.com/r/continuumio/miniconda3
FROM continuumio/miniconda3:latest

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_BREAK_SYSTEM_PACKAGES=1

# 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/

# Install linux packages and conda packages
RUN apt-get update && \
    apt-get install -y --no-install-recommends libgl1 && \
    apt-get clean && \
    # Install conda packages
    # mkl required to fix 'OSError: libmkl_intel_lp64.so.2: cannot open shared object file: No such file or directory'
    conda config --set solver libmamba && \
    conda install -y pytorch torchvision pytorch-cuda=12.1 -c pytorch -c nvidia && \
    conda install -y -c conda-forge ultralytics mkl && \
    conda clean -afy && \
    # Remove extra build files
    rm -rf /var/lib/apt/lists/* /root/.config/Ultralytics/persistent_cache.json

# Copy model
ADD https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt .

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

# Production builds: https://github.com/ultralytics/ultralytics/blob/main/.github/workflows/docker.yml
# Example (build): t=ultralytics/ultralytics:latest-conda && docker build -f docker/Dockerfile-conda -t $t .
# Example (push): docker push $t
# Example (pull): t=ultralytics/ultralytics:latest-conda && 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
