Skip to content

Commit a8d7852

Browse files
committed
Docker refresh: simplified & update to 16.04, cuda8, cudnn5, nccl
1 parent 8065c18 commit a8d7852

File tree

5 files changed

+49
-140
lines changed

5 files changed

+49
-140
lines changed

docker/Makefile

Lines changed: 0 additions & 50 deletions
This file was deleted.

docker/README.md

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
1-
# Caffe standalone Dockerfiles.
1+
### Running an official image
22

3-
The `standalone` subfolder contains docker files for generating both CPU and GPU executable images for Caffe. The images can be built using make, or by running:
3+
You can run one of the automatic [builds](https://hub.docker.com/r/bvlc/caffe)
4+
like this:
45

5-
```
6-
docker build -t caffe:cpu standalone/cpu
7-
```
8-
for example. (Here `gpu` can be substituted for `cpu`, but to keep the readme simple, only the `cpu` case will be discussed in detail).
6+
`docker run -ti bvlc/caffe caffe --version`
97

10-
Note that the GPU standalone requires a CUDA 7.5 capable driver to be installed on the system and [nvidia-docker] for running the Docker containers. Here it is generally sufficient to use `nvidia-docker` instead of `docker` in any of the commands mentioned.
8+
or for GPU support (You need a CUDA 8.0 capable driver and
9+
[nvidia-docker](https://github.com/NVIDIA/nvidia-docker)):
1110

12-
# Running Caffe using the docker image
11+
`nvidia-docker run -ti bvlc/caffe:gpu caffe --version`
1312

14-
In order to test the Caffe image, run:
15-
```
16-
docker run -ti caffe:cpu caffe --version
17-
```
18-
which should show a message like:
19-
```
20-
libdc1394 error: Failed to initialize libdc1394
21-
caffe version 1.0.0-rc3
22-
```
13+
You might see an error about libdc1394, ignore it.
2314

24-
One can also build and run the Caffe tests in the image using:
25-
```
26-
docker run -ti caffe:cpu bash -c "cd /opt/caffe/build; make runtest"
27-
```
15+
### Docker run options
2816

29-
In order to get the most out of the caffe image, some more advanced `docker run` options could be used. For example, running:
30-
```
31-
docker run -ti --volume=$(pwd):/workspace caffe:cpu caffe train --solver=example_solver.prototxt
32-
```
33-
will train a network defined in the `example_solver.prototxt` file in the current directory (`$(pwd)` is maped to the container volume `/workspace` using the `--volume=` Docker flag).
17+
By default caffe runs as root, thus any output files, e.g. snapshots, will be owned
18+
by root. It also runs by default in a container-private folder.
3419

35-
Note that docker runs all commands as root by default, and thus any output files (e.g. snapshots) generated will be owned by the root user. In order to ensure that the current user is used instead, the following command can be used:
36-
```
37-
docker run -ti --volume=$(pwd):/workspace -u $(id -u):$(id -g) caffe:cpu caffe train --solver=example_solver.prototxt
38-
```
39-
where the `-u` Docker command line option runs the commands in the container as the specified user, and the shell command `id` is used to determine the user and group ID of the current user. Note that the Caffe docker images have `/workspace` defined as the default working directory. This can be overridden using the `--workdir=` Docker command line option.
20+
You can change this using flags, like user (-u), current directory, and volumes (-w and -v).
21+
E.g. this behaves like the usual caffe executable:
4022

41-
# Other use-cases
23+
`docker run --rm -u $(id -u):$(id -g) -v $(pwd):$(pwd) -w $(pwd) bvlc/caffe caffe train --solver=example_solver.prototxt`
4224

43-
Although running the `caffe` command in the docker containers as described above serves many purposes, the container can also be used for more interactive use cases. For example, specifying `bash` as the command instead of `caffe` yields a shell that can be used for interactive tasks. (Since the caffe build requirements are included in the container, this can also be used to build and run local versions of caffe).
25+
Containers can also be used interactively, specifying e.g. `bash` or `ipython`
26+
instead of `caffe`.
4427

45-
Another use case is to run python scripts that depend on `caffe`'s Python modules. Using the `python` command instead of `bash` or `caffe` will allow this, and an interactive interpreter can be started by running:
4628
```
47-
docker run -ti caffe:cpu python
29+
docker run -ti bvlc/caffe ipython
30+
import caffe
31+
...
4832
```
49-
(`ipython` is also available in the container).
5033

51-
Since the `caffe/python` folder is also added to the path, the utility executable scripts defined there can also be used as executables. This includes `draw_net.py`, `classify.py`, and `detect.py`
34+
The caffe build requirements are included in the container, so this can be used to
35+
build and run custom versions of caffe. Also, `caffe/python` is in PATH, so python
36+
utilities can be used directly, e.g. `draw_net.py`, `classify.py`, or `detect.py`.
37+
38+
### Building images yourself
39+
40+
Examples:
41+
42+
`docker build -t caffe cpu`
43+
44+
`docker build -t caffe:gpu gpu`
45+
46+
You can also build Caffe and run the tests in the image:
5247

48+
`docker run -ti caffe bash -c "cd /opt/caffe/build; make runtest"`

docker/standalone/cpu/Dockerfile renamed to docker/cpu/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM ubuntu:14.04
2-
1+
FROM ubuntu:16.04
2+
LABEL maintainer [email protected]
33

44
RUN apt-get update && apt-get install -y --no-install-recommends \
55
build-essential \
@@ -20,17 +20,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2020
python-dev \
2121
python-numpy \
2222
python-pip \
23+
python-setuptools \
2324
python-scipy && \
2425
rm -rf /var/lib/apt/lists/*
2526

2627
ENV CAFFE_ROOT=/opt/caffe
2728
WORKDIR $CAFFE_ROOT
2829

29-
# FIXME: clone a specific git tag and use ARG instead of ENV once DockerHub supports this.
30-
ENV CLONE_TAG=master
30+
# FIXME: use ARG instead of ENV once DockerHub supports this
31+
ENV CLONE_TAG=1.0.0-rc4
3132

3233
RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/BVLC/caffe.git . && \
33-
for req in $(cat python/requirements.txt) pydot; do pip install $req; done && \
34+
pip install --upgrade pip && \
35+
cd python && for req in $(cat requirements.txt) pydot; do pip install $req; done && cd .. && \
3436
mkdir build && cd build && \
3537
cmake -DCPU_ONLY=1 .. && \
3638
make -j"$(nproc)"

docker/standalone/gpu/Dockerfile renamed to docker/gpu/Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
2-
1+
FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04
2+
LABEL maintainer [email protected]
33

44
RUN apt-get update && apt-get install -y --no-install-recommends \
55
build-essential \
@@ -20,19 +20,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2020
python-dev \
2121
python-numpy \
2222
python-pip \
23+
python-setuptools \
2324
python-scipy && \
2425
rm -rf /var/lib/apt/lists/*
2526

2627
ENV CAFFE_ROOT=/opt/caffe
2728
WORKDIR $CAFFE_ROOT
2829

29-
# FIXME: clone a specific git tag and use ARG instead of ENV once DockerHub supports this.
30-
ENV CLONE_TAG=master
30+
# FIXME: use ARG instead of ENV once DockerHub supports this
31+
ENV CLONE_TAG=1.0.0-rc4
3132

3233
RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/BVLC/caffe.git . && \
33-
for req in $(cat python/requirements.txt) pydot; do pip install $req; done && \
34+
pip install --upgrade pip && \
35+
cd python && for req in $(cat requirements.txt) pydot; do pip install $req; done && cd .. && \
36+
git clone https://github.com/NVIDIA/nccl.git && cd nccl && make -j install && cd .. && rm -rf nccl && \
3437
mkdir build && cd build && \
35-
cmake -DUSE_CUDNN=1 .. && \
38+
cmake -DUSE_CUDNN=1 -DUSE_NCCL=1 .. && \
3639
make -j"$(nproc)"
3740

3841
ENV PYCAFFE_ROOT $CAFFE_ROOT/python

docker/templates/Dockerfile.template

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)