[Feature]: Add dockerfile (#347)

* Add dockerfile

* update README

* resolve comments

* Remove unnecessary commands

* Simplify the dockerfile

* enable to specific mmengine version

* Update README.md

* revert
This commit is contained in:
Zaida Zhou 2022-09-07 20:26:17 +08:00 committed by GitHub
parent 34bd3e535e
commit ac5e79c6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 0 deletions

65
docker/README.md Normal file
View File

@ -0,0 +1,65 @@
# Docker images
There are two `Dockerfile` files to build docker images, one to build an image with the mmengine package and the other with the mmengine development environment.
```text
.
|-- README.md
|-- dev # build with mmengine development environment
| `-- Dockerfile
`-- release # build with mmengine package
`-- Dockerfile
```
## Build docker images
### Build with mmengine package
Build with local repository
```bash
git clone https://github.com/open-mmlab/mmengine.git && cd mmengine
docker build -t mmengine -f docker/release/Dockerfile .
```
Or build with remote repository
```bash
docker build -t mmengine https://github.com/open-mmlab/mmengine.git#main:docker/release
```
The [Dockerfile](release/Dockerfile) installs the latest released version of mmengine by default, but you can specify mmengine versions to install expected versions.
```bash
docker image build -t mmengine -f docker/release/Dockerfile --build-arg MMENGINE=0.1.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 mmengine -f docker/release/Dockerfile \
--build-arg PYTORCH=1.9.0 \
--build-arg CUDA=11.1 \
--build-arg CUDNN=8 .
```
More available versions of PyTorch and CUDA can be found at [dockerhub/pytorch](https://hub.docker.com/r/pytorch/pytorch/tags).
### Build with mmengine development environment
If you want to build an docker image with the mmengine development environment, you can use the following command
```bash
git clone https://github.com/open-mmlab/mmengine.git && cd mmengine
docker build -t mmengine -f docker/dev/Dockerfile .
```
## Run images
```bash
docker run --gpus all --shm-size=8g -it mmengine
```
See [docker run](https://docs.docker.com/engine/reference/commandline/run/) for more usages.

24
docker/dev/Dockerfile Normal file
View File

@ -0,0 +1,24 @@
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
# Build mmengine from source with develop mode
RUN git clone https://github.com/open-mmlab/mmengine.git /mmengine
WORKDIR /mmengine
RUN git rev-parse --short HEAD
RUN pip install --no-cache-dir -e .[all] -v && pip install pre-commit && pre-commit install
# Verify the installation
RUN python -c 'from mmengine.utils.dl_utils import collect_env;print(collect_env())'

23
docker/release/Dockerfile Normal file
View File

@ -0,0 +1,23 @@
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 mmengine
ARG MMENGINE=""
RUN if [ "${MMENGINE}" = "" ]; then pip install -U openmim && mim install mmengine; else pip install -U openmim && mim install mmengine==${MMENGINE}; fi
# Verify the installation
RUN python -c 'from mmengine.utils.dl_utils import collect_env;print(collect_env())'