diff --git a/docker/Dockerfile b/docker/Dockerfile index 8bf3ec44a0..605ca0a4c5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,6 +6,11 @@ FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime RUN pip install --no-cache-dir nvidia-tensorrt --index-url https://pypi.ngc.nvidia.com +# Set environment variables +ENV APP_HOME /usr/src/ultralytics +# Avoid DDP error "MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library" https://github.com/pytorch/pytorch/issues/37377 +ENV MKL_THREADING_LAYER=GNU + # 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 \ @@ -22,12 +27,12 @@ RUN apt update \ RUN apt upgrade --no-install-recommends -y openssl tar # Create working directory -WORKDIR /usr/src/ultralytics +WORKDIR $APP_HOME -# Copy contents -# COPY . /usr/src/ultralytics # git permission issues inside container -RUN git clone https://github.com/ultralytics/ultralytics -b main /usr/src/ultralytics -ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt /usr/src/ultralytics/ +# Copy contents and assign permissions +COPY . $APP_HOME +RUN chown -R root:root $APP_HOME +ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME # Install pip packages RUN python3 -m pip install --upgrade pip wheel @@ -44,11 +49,6 @@ RUN pip install --no-cache-dir numpy==1.23.5 # Remove exported models RUN rm -rf tmp -# Set environment variables -ENV OMP_NUM_THREADS=1 -# Avoid DDP error "MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library" https://github.com/pytorch/pytorch/issues/37377 -ENV MKL_THREADING_LAYER=GNU - # Usage Examples ------------------------------------------------------------------------------------------------------- diff --git a/docker/Dockerfile-arm64 b/docker/Dockerfile-arm64 index 0a03410dbe..bc187f74b6 100644 --- a/docker/Dockerfile-arm64 +++ b/docker/Dockerfile-arm64 @@ -6,6 +6,9 @@ # Start FROM Debian image for arm64v8 https://hub.docker.com/r/arm64v8/debian (new) FROM arm64v8/debian:bookworm-slim +# Set environment variables +ENV APP_HOME /usr/src/ultralytics + # 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 \ @@ -19,12 +22,12 @@ RUN apt update \ && apt install --no-install-recommends -y python3-pip git zip curl htop gcc libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 build-essential # Create working directory -WORKDIR /usr/src/ultralytics +WORKDIR $APP_HOME -# Copy contents -# COPY . /usr/src/ultralytics # git permission issues inside container -RUN git clone https://github.com/ultralytics/ultralytics -b main /usr/src/ultralytics -ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt /usr/src/ultralytics/ +# Copy contents and assign permissions +COPY . $APP_HOME +RUN chown -R root:root $APP_HOME +ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME # Remove python3.11/EXTERNALLY-MANAGED to avoid 'externally-managed-environment' issue, Debian 12 Bookworm error RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED diff --git a/docker/Dockerfile-cpu b/docker/Dockerfile-cpu index feb8d5357f..212027478d 100644 --- a/docker/Dockerfile-cpu +++ b/docker/Dockerfile-cpu @@ -5,6 +5,9 @@ # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu FROM ubuntu:23.10 +# Set environment variables +ENV APP_HOME /usr/src/ultralytics + # 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 \ @@ -16,12 +19,13 @@ RUN apt update \ && apt install --no-install-recommends -y python3-pip git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 # Create working directory -WORKDIR /usr/src/ultralytics +WORKDIR $APP_HOME -# Copy contents -# COPY . /usr/src/ultralytics # git permission issues inside container -RUN git clone https://github.com/ultralytics/ultralytics -b main /usr/src/ultralytics -ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt /usr/src/ultralytics/ +# Copy contents (previously used git clone to avoid permission errors) +COPY . $APP_HOME +RUN chown -R root:root $APP_HOME +# RUN git clone https://github.com/ultralytics/ultralytics -b main $APP_HOME +ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME # Remove python3.11/EXTERNALLY-MANAGED or use 'pip install --break-system-packages' avoid 'externally-managed-environment' Ubuntu nightly error RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED diff --git a/docker/Dockerfile-jetson b/docker/Dockerfile-jetson index d518b58a1b..1646169710 100644 --- a/docker/Dockerfile-jetson +++ b/docker/Dockerfile-jetson @@ -5,6 +5,9 @@ # Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-pytorch FROM nvcr.io/nvidia/l4t-pytorch:r35.2.1-pth2.0-py3 +# Set environment variables +ENV APP_HOME /usr/src/ultralytics + # 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 \ @@ -18,12 +21,12 @@ RUN apt update \ && apt install --no-install-recommends -y gcc git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 # Create working directory -WORKDIR /usr/src/ultralytics +WORKDIR $APP_HOME -# Copy contents -# COPY . /usr/src/ultralytics # git permission issues inside container -RUN git clone https://github.com/ultralytics/ultralytics -b main /usr/src/ultralytics -ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt /usr/src/ultralytics/ +# Copy contents and assign permissions +COPY . $APP_HOME +RUN chown -R root:root $APP_HOME +ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME # Remove opencv-python from Ultralytics dependencies as it conflicts with opencv-python installed in base image RUN grep -v "opencv-python" pyproject.toml > temp.toml && mv temp.toml pyproject.toml @@ -37,9 +40,6 @@ RUN pip install onnxruntime_gpu-1.15.1-cp38-cp38-linux_aarch64.whl RUN pip install --no-cache-dir tqdm matplotlib pyyaml psutil pandas onnx RUN pip install --no-cache-dir -e ".[export]" -# Set environment variables -ENV OMP_NUM_THREADS=1 - # Usage Examples ------------------------------------------------------------------------------------------------------- diff --git a/docker/Dockerfile-python b/docker/Dockerfile-python index db297be3df..1268647f54 100644 --- a/docker/Dockerfile-python +++ b/docker/Dockerfile-python @@ -5,6 +5,9 @@ # Use the official Python 3.10 slim-bookworm as base image FROM python:3.10-slim-bookworm +# Set environment variables +ENV APP_HOME /usr/src/ultralytics + # 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 \ @@ -16,12 +19,12 @@ RUN apt update \ && apt install --no-install-recommends -y python3-pip git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 # Create working directory -WORKDIR /usr/src/ultralytics +WORKDIR $APP_HOME -# Copy contents -# COPY . /usr/src/ultralytics # git permission issues inside container -RUN git clone https://github.com/ultralytics/ultralytics -b main /usr/src/ultralytics -ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt /usr/src/ultralytics/ +# Copy contents and assign permissions +COPY . $APP_HOME +RUN chown -R root:root $APP_HOME +ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME # Remove python3.11/EXTERNALLY-MANAGED or use 'pip install --break-system-packages' avoid 'externally-managed-environment' Ubuntu nightly error # RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED