Dockerfile 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. # Builds ultralytics/ultralytics:latest image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
  3. # Image is CUDA-optimized for YOLOv8 single/multi-GPU training and inference
  4. # Start FROM PyTorch image https://hub.docker.com/r/pytorch/pytorch or nvcr.io/nvidia/pytorch:23.03-py3
  5. FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
  6. # Set environment variables
  7. ENV APP_HOME /usr/src/ultralytics
  8. # Avoid DDP error "MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library" https://github.com/pytorch/pytorch/issues/37377
  9. ENV MKL_THREADING_LAYER=GNU
  10. # Downloads to user config dir
  11. ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \
  12. https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \
  13. /root/.config/Ultralytics/
  14. # Install linux packages
  15. # g++ required to build 'tflite_support' and 'lap' packages, libusb-1.0-0 required for 'tflite_support' package
  16. # libsm6 required by libqxcb to create QT-based windows for visualization; set 'QT_DEBUG_PLUGINS=1' to test in docker
  17. RUN apt update \
  18. && apt install --no-install-recommends -y gcc git zip unzip wget curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 libsm6
  19. # Security updates
  20. # https://security.snyk.io/vuln/SNYK-UBUNTU1804-OPENSSL-3314796
  21. RUN apt upgrade --no-install-recommends -y openssl tar
  22. # Create working directory
  23. WORKDIR $APP_HOME
  24. # Copy contents and assign permissions
  25. COPY . $APP_HOME
  26. RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
  27. ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
  28. # Install pip packages
  29. RUN python3 -m pip install --upgrade pip wheel
  30. # Pin TensorRT-cu12==10.1.0 to avoid 10.2.0 bug https://github.com/ultralytics/ultralytics/pull/14239 (note -cu12 must be used)
  31. RUN pip install --no-cache-dir -e ".[export]" "tensorrt-cu12==10.1.0" "albumentations>=1.4.6" comet pycocotools
  32. # Run exports to AutoInstall packages
  33. # Edge TPU export fails the first time so is run twice here
  34. RUN yolo export model=tmp/yolov8n.pt format=edgetpu imgsz=32 || yolo export model=tmp/yolov8n.pt format=edgetpu imgsz=32
  35. RUN yolo export model=tmp/yolov8n.pt format=ncnn imgsz=32
  36. # Requires <= Python 3.10, bug with paddlepaddle==2.5.0 https://github.com/PaddlePaddle/X2Paddle/issues/991
  37. RUN pip install --no-cache-dir "paddlepaddle>=2.6.0" x2paddle
  38. # Fix error: `np.bool` was a deprecated alias for the builtin `bool` segmentation error in Tests
  39. RUN pip install --no-cache-dir numpy==1.23.5
  40. # Remove exported models
  41. RUN rm -rf tmp
  42. # Usage Examples -------------------------------------------------------------------------------------------------------
  43. # Build and Push
  44. # t=ultralytics/ultralytics:latest && sudo docker build -f docker/Dockerfile -t $t . && sudo docker push $t
  45. # Pull and Run with access to all GPUs
  46. # t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all $t
  47. # Pull and Run with access to GPUs 2 and 3 (inside container CUDA devices will appear as 0 and 1)
  48. # t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus '"device=2,3"' $t
  49. # Pull and Run with local directory access
  50. # t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
  51. # Kill all
  52. # sudo docker kill $(sudo docker ps -q)
  53. # Kill all image-based
  54. # sudo docker kill $(sudo docker ps -qa --filter ancestor=ultralytics/ultralytics:latest)
  55. # DockerHub tag update
  56. # t=ultralytics/ultralytics:latest tnew=ultralytics/ultralytics:v6.2 && sudo docker pull $t && sudo docker tag $t $tnew && sudo docker push $tnew
  57. # Clean up
  58. # sudo docker system prune -a --volumes
  59. # Update Ubuntu drivers
  60. # https://www.maketecheasier.com/install-nvidia-drivers-ubuntu/
  61. # DDP test
  62. # python -m torch.distributed.run --nproc_per_node 2 --master_port 1 train.py --epochs 3
  63. # GCP VM from Image
  64. # docker.io/ultralytics/ultralytics:latest