Skip to content

Commit

Permalink
Simplify Dockerfile WORKDIR (ultralytics#14750)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
  • Loading branch information
glenn-jocher authored Jul 28, 2024
1 parent f8454f1 commit 01977da
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 47 deletions.
9 changes: 4 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime

# 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

Expand All @@ -26,12 +25,12 @@ RUN apt update \
RUN apt upgrade --no-install-recommends -y openssl tar

# Create working directory
WORKDIR $APP_HOME
WORKDIR /ultralytics

# Copy contents and assign permissions
COPY . $APP_HOME
COPY . .
RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# Install pip packages
RUN python3 -m pip install --upgrade pip wheel
Expand Down Expand Up @@ -62,7 +61,7 @@ RUN rm -rf tmp
# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus '"device=2,3"' $t

# Pull and Run with local directory access
# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/shared/datasets:/datasets $t

# Kill all
# sudo docker kill $(sudo docker ps -q)
Expand Down
11 changes: 4 additions & 7 deletions docker/Dockerfile-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# 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 \
Expand All @@ -21,12 +18,12 @@ RUN apt update \
&& apt install --no-install-recommends -y python3-pip git zip unzip wget curl htop gcc libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0

# Create working directory
WORKDIR $APP_HOME
WORKDIR /ultralytics

# Copy contents and assign permissions
COPY . $APP_HOME
COPY . .
RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# Remove python3.11/EXTERNALLY-MANAGED to avoid 'externally-managed-environment' issue, Debian 12 Bookworm error
RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED
Expand All @@ -51,4 +48,4 @@ RUN ln -sf /usr/bin/python3 /usr/bin/python
# t=ultralytics/ultralytics:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host $t

# Pull and Run with local volume mounted
# t=ultralytics/ultralytics:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
# t=ultralytics/ultralytics:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t
2 changes: 1 addition & 1 deletion docker/Dockerfile-conda
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ RUN conda config --set solver libmamba && \
# t=ultralytics/ultralytics:latest-conda && sudo docker pull $t && sudo docker run -it --ipc=host $t

# Pull and Run with local volume mounted
# t=ultralytics/ultralytics:latest-conda && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
# t=ultralytics/ultralytics:latest-conda && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t
11 changes: 4 additions & 7 deletions docker/Dockerfile-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# 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 \
Expand All @@ -19,12 +16,12 @@ RUN apt update \
&& apt install --no-install-recommends -y python3-pip git zip unzip wget curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0

# Create working directory
WORKDIR $APP_HOME
WORKDIR /ultralytics

# Copy contents (previously used git clone to avoid permission errors)
COPY . $APP_HOME
COPY . .
RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# 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
Expand Down Expand Up @@ -57,4 +54,4 @@ RUN ln -sf /usr/bin/python3 /usr/bin/python
# t=ultralytics/ultralytics:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host --name NAME $t

# Pull and Run with local volume mounted
# t=ultralytics/ultralytics:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
# t=ultralytics/ultralytics:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t
11 changes: 4 additions & 7 deletions docker/Dockerfile-jetson-jetpack4
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-cuda
FROM nvcr.io/nvidia/l4t-cuda:10.2.460-runtime

# 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 \
Expand All @@ -27,12 +24,12 @@ RUN ln -sf /usr/bin/python3.8 /usr/bin/python3
RUN ln -s /usr/bin/pip3 /usr/bin/pip

# Create working directory
WORKDIR $APP_HOME
WORKDIR /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
COPY . .
RUN chown -R root:root .
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# Download onnxruntime-gpu 1.8.0 and tensorrt 8.2.0.6
# Other versions can be seen in https://elinux.org/Jetson_Zoo and https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
Expand Down
9 changes: 3 additions & 6 deletions docker/Dockerfile-jetson-jetpack5
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# 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 \
Expand All @@ -21,12 +18,12 @@ RUN apt update \
&& 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

# Create working directory
WORKDIR $APP_HOME
WORKDIR /ultralytics

# Copy contents and assign permissions
COPY . $APP_HOME
COPY . .
RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# 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
Expand Down
11 changes: 4 additions & 7 deletions docker/Dockerfile-jetson-jetpack6
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-jetpack
FROM nvcr.io/nvidia/l4t-jetpack:r36.3.0

# 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 \
Expand All @@ -18,12 +15,12 @@ RUN apt update && \
apt install --no-install-recommends -y git python3-pip libopenmpi-dev libopenblas-base libomp-dev

# Create working directory
WORKDIR $APP_HOME
WORKDIR /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
COPY . .
RUN chown -R root:root .
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# Download onnxruntime-gpu 1.18.0 from https://elinux.org/Jetson_Zoo and https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
ADD https://nvidia.box.com/shared/static/48dtuob7meiw6ebgfsfqakc9vse62sg4.whl onnxruntime_gpu-1.18.0-cp310-cp310-linux_aarch64.whl
Expand Down
11 changes: 4 additions & 7 deletions docker/Dockerfile-python
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# 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 \
Expand All @@ -19,12 +16,12 @@ RUN apt update \
&& apt install --no-install-recommends -y python3-pip git zip unzip wget curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0

# Create working directory
WORKDIR $APP_HOME
WORKDIR /ultralytics

# Copy contents and assign permissions
COPY . $APP_HOME
COPY . .
RUN git remote set-url origin https://github.com/ultralytics/ultralytics.git
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt $APP_HOME
ADD https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt .

# 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
Expand Down Expand Up @@ -54,4 +51,4 @@ RUN rm -rf tmp
# t=ultralytics/ultralytics:latest-python && sudo docker pull $t && sudo docker run -it --ipc=host $t

# Pull and Run with local volume mounted
# t=ultralytics/ultralytics:latest-python && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/usr/src/datasets $t
# t=ultralytics/ultralytics:latest-python && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t

0 comments on commit 01977da

Please sign in to comment.