From 393ed0b7a8c5f93454d245fe5ab76394dd3ba838 Mon Sep 17 00:00:00 2001 From: jsun Date: Sun, 11 Aug 2024 22:09:58 +0900 Subject: [PATCH] [add] add files to build Docekr image for cvtk package. --- docker/Dockerfile | 42 +++++++++++++++++++++++++++++++++++++++ docker/README.md | 22 ++++++++++++++++++++ docker/build.sh | 7 +++++++ docker/docker-compose.yml | 27 +++++++++++++++++++++++++ docker/run.sh | 8 ++++++++ 5 files changed, 106 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/build.sh create mode 100644 docker/docker-compose.yml create mode 100644 docker/run.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..a1a19e7 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,42 @@ + +ARG PYTORCH="2.3.1" +ARG CUDA="12.1" +ARG CUDNN="8" +FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel + +ARG UID +ARG GID +ARG USERNAME +ARG GROUPNAME + +#setup environment +ENV FORCE_CUDA="1" \ + TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6+PTX" \ + PATH="/usr/local/cuda/bin:$PATH" \ + TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \ + CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" MMCV_WITH_OPS="1" + +# installation +RUN apt update \ + && apt install -y git libgl1 libglib2.0-0 ffmpeg libturbojpeg libsm6 libxext6 ninja-build libxrender-dev \ + && apt clean \ + && rm -rf /var/lib/apt/lists/* \ + && git clone https://github.com/open-mmlab/mmcv.git -b v2.1.0 mmcv-v2.1.0 \ + && cd mmcv-v2.1.0 \ + && pip install --no-cache-dir -r ./requirements/build.txt \ + && pip install --no-cache-dir .[all] -v \ + && cd .. \ + && git clone https://github.com/open-mmlab/mmdetection.git -b v3.3.0 mmdet-v3.3.0 \ + && cd mmdet-v3.3.0 \ + && pip install --no-cache-dir -r ./requirements/build.txt \ + && pip install --no-cache-dir . -v \ + && cd .. \ + && rm -rf ./mmcv-v2.1.0 ./mmdet-v3.3.0 + + +RUN groupadd -g ${GID} ${GROUPNAME} -f \ + && useradd -m -s /bin/bash -u ${UID} -g ${GID} ${USERNAME} \ + && echo 'export PATH=~/.local/bin:${PATH}' >> /home/${USERNAME}/.bashrc +USER ${USERNAME} +RUN pip install -U cvtk +WORKDIR /home/${USERNAME} diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..97a75ce --- /dev/null +++ b/docker/README.md @@ -0,0 +1,22 @@ +# Dockerfile for cvtk package + +To build the cvtk Docker image, run the following command. + +```bash +bash build.sh +``` + + +To start the Docker container for the cvtk package after build, +run the following command. +If necessary, the directory to mount and the port number +to communicate with the host +can be changed by editing the docker-compose.yml file. + + +```bash +bash run.sh +``` + + + diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 0000000..d292b29 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,7 @@ +#!/bash/bin + +sudo env USERNAME="$(id -un)" docker compose build \ + --build-arg UID="$(id -u)" \ + --build-arg GID="$(id -g)" \ + --build-arg USERNAME="$(id -un)" \ + --build-arg GROUPNAME="$(id -un)" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..42ca43c --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,27 @@ +services: + devel-env: + image: "devel:${USERNAME}" + build: + context: . + dockerfile: Dockerfile + args: + - UID:1000 + - GID:1000 + - USERNAME:ubuntu + - GROUPNAME:ubuntu + container_name: "DevEnv-${USERNAME}" + network_mode: host + ports: + - "80:80" + - "8080:8080" + shm_size: "12gb" + deploy: + resources: + reservations: + devices: + - capabilities: [gpu] + volumes: + # mounting home directory result in the ambiguity of shell configurations (e.g. .bashrc) + - type: bind + source: "/home/${USERNAME}/workspace" + target: "/home/${USERNAME}/workspace" diff --git a/docker/run.sh b/docker/run.sh new file mode 100644 index 0000000..682ae28 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,8 @@ +#!/bash/bin + +sudo USERNAME="$(id -un)" docker compose run -it --rm \ + -e UID="$(id -u)" \ + -e GID="$(id -g)" \ + -e USERNAME="$(id -un)" \ + -e GROUPNAME="$(id -un)" \ + devel-env