[Feature] Add Dockerfile ()

* Add Dockerfiles

remove Dockerfile in root directory

minor fix

minor fix

* improve dockerfile

* refine
pull/2090/head
Zaida Zhou 2022-07-01 16:23:28 +08:00 committed by GitHub
parent c344c11004
commit 9fffcbc9cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 7 deletions
.github/workflows

View File

@ -8,6 +8,7 @@ on:
- 'docs/**'
- 'examples/**'
- '.dev_scripts/**'
- 'docker/**'
pull_request:
paths-ignore:
@ -16,6 +17,7 @@ on:
- 'docs/**'
- 'examples/**'
- '.dev_scripts/**'
- 'docker/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

View File

@ -1,7 +0,0 @@
FROM python:3.7
WORKDIR /mmcv
COPY . /mmcv
RUN pip install -e .

70
docker/README.md 100644
View File

@ -0,0 +1,70 @@
# Docker images
There are two `Dockerfile` files to build docker images, one to build an image with the mmcv-full pre-built package and the other with the mmcv development environment.
```text
.
|-- README.md
|-- dev # build with mmcv development environment
| `-- Dockerfile
`-- release # build with mmcv pre-built package
`-- Dockerfile
```
## Build docker images
### Build with mmcv pre-built package
Build with local repository
```bash
git clone https://github.com/open-mmlab/mmcv.git && cd mmcv
docker build -t mmcv -f docker/release/Dockerfile .
```
Or build with remote repository
```bash
docker build -t mmcv https://github.com/open-mmlab/mmcv.git#master:docker/release
```
The [Dockerfile](release/Dockerfile) installs latest released version of mmcv-full by default, but you can specify mmcv versions to install expected versions.
```bash
docker image build -t mmcv -f docker/release/Dockerfile --build-arg MMCV=1.5.0 .
```
If you also want to use other versions of PyTorch and CUDA, you can also pass them when building docker images.
An example to build an image with PyTorch 1.11 and CUDA 11.3.
```bash
docker build -t mmcv -f docker/release/Dockerfile \
--build-arg PYTORCH=1.9.0 \
--build-arg CUDA=11.1 \
--build-arg CUDNN=8 \
--build-arg MMCV=1.5.0 .
```
More available versions of PyTorch and CUDA can be found at [dockerhub/pytorch](https://hub.docker.com/r/pytorch/pytorch/tags).
### Build with mmcv development environment
If you want to build an docker image with the mmcv development environment, you can use the following command
```bash
git clone https://github.com/open-mmlab/mmcv.git && cd mmcv
docker build -t mmcv -f docker/dev/Dockerfile --build-arg CUDA_ARCH=7.5 .
```
Note that `CUDA_ARCH` is the cumpute capability of your GPU and you can find it at [Compute Capability](https://developer.nvidia.com/cuda-gpus#compute).
The building process may take 10 minutes or more.
## Run images
```bash
docker run --gpus all --shm-size=8g -it mmcv
```
See [docker run](https://docs.docker.com/engine/reference/commandline/run/) for more usages.

View File

@ -0,0 +1,32 @@
ARG PYTORCH="1.8.1"
ARG CUDA="10.2"
ARG CUDNN="7"
FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
# To fix GPG key error when running apt-get update
RUN rm /etc/apt/sources.list.d/cuda.list \
&& rm /etc/apt/sources.list.d/nvidia-ml.list \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
# Install git and system dependencies for opencv-python
RUN apt-get update && apt-get install -y git \
&& apt-get update && apt-get install -y libgl1 libglib2.0-0
# Install system dependencies for unit tests
RUN apt-get install -y ffmpeg libturbojpeg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# build mmcv-full from source with develop mode
ARG HTTPS_PROXY=""
ENV https_proxy=${HTTPS_PROXY}
ENV FORCE_CUDA="1"
ENV MMCV_WITH_OPS="1"
ARG CUDA_ARCH=""
ENV TORCH_CUDA_ARCH_LIST=${CUDA_ARCH}
RUN git clone https://github.com/open-mmlab/mmcv.git /mmcv
WORKDIR /mmcv
RUN git rev-parse --short HEAD
RUN pip install --no-cache-dir -e .[all] -v && pip install pre-commit && pre-commit install

View File

@ -0,0 +1,20 @@
ARG PYTORCH="1.8.1"
ARG CUDA="10.2"
ARG CUDNN="7"
FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
# To fix GPG key error when running apt-get update
RUN rm /etc/apt/sources.list.d/cuda.list \
&& rm /etc/apt/sources.list.d/nvidia-ml.list \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub \
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
# Install system dependencies for opencv-python
RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install mmcv-full
ARG MMCV="1.5.1"
RUN pip install openmim && mim install mmcv-full==${MMCV} && python -c 'import mmcv;print(mmcv.__version__)'