Skip to content

Commit

Permalink
Optimize Dockerfile: Use official PyTorch base image and remove redun…
Browse files Browse the repository at this point in the history
…dant steps

- Switched to  base image, which includes PyTorch and CUDA, eliminating the need to install them separately.
- Removed redundant Python setup, including
Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  inspect                     Inspect the python environment.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  --require-virtualenv        Allow pip to only run in a virtual environment;
                              exit with an error otherwise.
  --python <python>           Run pip with the specified Python interpreter.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              scheme://[user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted,
                              even though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future. upgrade and manual PyTorch installation.
- Streamlined the installation of system dependencies and Python packages.

Instructions:

1. Build the Docker image:
   docker build -t my_pytorch_image .
2. List all Docker images:
   docker images
3. Run the Docker container with X11 forwarding for GUI support:
   docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix/ -e DISPLAY= my_pytorch_image
  • Loading branch information
healthonrails committed Oct 14, 2024
1 parent 2e9331f commit ac83505
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,59 @@
# 1. https://github.com/facebookresearch/detectron2/blob/main/docker/Dockerfile
# 2. https://github.com/wkentaro/labelme/blob/main/docker/Dockerfile

FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04
# Use the official PyTorch image as the base
FROM pytorch/pytorch:2.4.1-cuda11.8-cudnn9-devel
LABEL maintainer "Chen Yang <[email protected]>"

ENV DEBIAN_FRONTEND=noninteractive

RUN \
apt-get update -qq && \
apt-get install -qq -y \
# Install system dependencies
RUN apt-get update -qq && \
apt-get install -qq -y \
git \
wget \
ca-certificates \
python3 \
python3-pip \
python3-matplotlib \
python3-pyqt5 \
python3-opencv \
python3-dev \
sudo \
ninja-build\
ninja-build \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*

RUN python3 -m pip install -U pip setuptools wheel
RUN ln -sv /usr/bin/python3 /usr/bin/python

# create a non-root user
# Create a non-root user
ARG USER_ID=1000
RUN useradd -m --no-log-init --system --uid ${USER_ID} annoliduser -g sudo
RUN useradd -m --no-log-init --system --uid ${USER_ID} annoliduser -g sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER annoliduser
WORKDIR /home/annoliduser

# Set the path for user-installed packages
ENV PATH="/home/annoliduser/.local/bin:${PATH}"
RUN wget https://bootstrap.pypa.io/pip/3.6/get-pip.py && \
python3 get-pip.py --user && \
rm get-pip.py

# install dependencies
RUN pip install --user tensorboard cmake
RUN pip install --user torch==1.9 torchvision==0.10 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# Install python dependencies
RUN pip install --user tensorboard cmake 'git+https://github.com/facebookresearch/fvcore'

RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
# install detectron2
# Clone and install detectron2
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
# set FORCE_CUDA because during `docker build` cuda is not accessible
ENV FORCE_CUDA="1"
# This will by default build detectron2 for all common cuda architectures and take a lot more time,
# because inside `docker build`, there is no way to tell which architecture will be used.
ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"

RUN pip install --user -e detectron2_repo

# Clone and install annolid
RUN git clone --recurse-submodules https://github.com/healthonrails/annolid.git
# RUN git clone --recurse-submodules -b docker_bug --single-branch https://github.com/jeremyforest/annolid.git
RUN pip install --user -e annolid

# Set a fixed model cache directory.
RUN pip install --user numpy==1.24.4
RUN pip install --user decord==0.4.0
RUN rm -rf /home/annoliduser/.local/lib/python3.11/site-packages/cv2/qt/plugins/*
# Set a fixed model cache directory
ENV FVCORE_CACHE="/tmp"
WORKDIR /home/annoliduser/annolid

# Set language environment
ENV LANG en-US

ENTRYPOINT [ "annolid" ]
# Entry point for annolid
ENTRYPOINT [ "annolid" ]

0 comments on commit ac83505

Please sign in to comment.