docker_install_en.rst 6.3 KB
Newer Older
Y
Yi Wang 已提交
1 2
PaddlePaddle in Docker Containers
=================================
3

Y
Yi Wang 已提交
4 5 6 7 8 9
Docker container is currently the only officially-supported way to
running PaddlePaddle.  This is reasonable as Docker now runs on all
major operating systems including Linux, Mac OS X, and Windows.
Please be aware that you will need to change `Dockers settings
<https://github.com/PaddlePaddle/Paddle/issues/627>`_ to make full use
of your hardware resource on Mac OS X and Windows.
10 11


L
liaogang 已提交
12 13
Usage of CPU-only and GPU Images
----------------------------------
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

For each version of PaddlePaddle, we release 2 Docker images, a
CPU-only one and a CUDA GPU one.  We do so by configuring
`dockerhub.com <https://hub.docker.com/r/paddledev/paddle/>`_
automatically generate the latest docker images `paddledev/paddle:0.10.0rc1-cpu`
and `paddledev/paddle:0.10.0rc1-gpu`.

To run the CPU-only image as an interactive container:

.. code-block:: bash

    docker run -it --rm paddledev/paddle:0.10.0rc1-cpu /bin/bash

or, we can run it as a daemon container

.. code-block:: bash

    docker run -d -p 2202:22 -p 8888:8888 paddledev/paddle:0.10.0rc1-cpu

and SSH to this container using password :code:`root`:

.. code-block:: bash

    ssh -p 2202 root@localhost

An advantage of using SSH is that we can connect to PaddlePaddle from
more than one terminals.  For example, one terminal running vi and
another one running Python interpreter.  Another advantage is that we
can run the PaddlePaddle container on a remote server and SSH to it
from a laptop.

Above methods work with the GPU image too -- just please don't forget
L
liaogang 已提交
46 47 48 49 50 51 52 53 54
to install GPU driver. To support GPU driver, we recommend to use 
[nvidia-docker](https://github.com/NVIDIA/nvidia-docker). Run using

.. code-block:: bash

    nvidia-docker run -it --rm paddledev/paddle:0.10.0rc1-gpu /bin/bash


**Note:** If you would have a problem running nvidia-docker, you may try the old method we have used (not recommended).
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

.. code-block:: bash

    export CUDA_SO="$(\ls /usr/lib64/libcuda* | xargs -I{} echo '-v {}:{}') $(\ls /usr/lib64/libnvidia* | xargs -I{} echo '-v {}:{}')"
    export DEVICES=$(\ls /dev/nvidia* | xargs -I{} echo '--device {}:{}')
    docker run ${CUDA_SO} ${DEVICES} -it paddledev/paddle:0.10.0rc1-gpu


PaddlePaddle Book
------------------

The Jupyter Notebook is an open-source web application that allows
you to create and share documents that contain live code, equations,
visualizations and explanatory text in a single browser.

PaddlePaddle Book is an interactive Jupyter Notebook for users and developers. 
We already exposed port 8888 for this book. If you want to
dig deeper into deep learning, PaddlePaddle Book definitely is your best choice.

Once you are inside the container, simply issue the command:

.. code-block:: bash
        
    jupyter notebook

Then, you would back and paste the address into the local browser:
    
.. code-block:: text

    http://localhost:8888/

That's all. Enjoy your journey!


Non-AVX Images
--------------

Please be aware that the CPU-only and the GPU images both use the AVX
instruction set, but old computers produced before 2008 do not support
AVX.  The following command checks if your Linux computer supports
AVX:

.. code-block:: bash

   if cat /proc/cpuinfo | grep -i avx; then echo Yes; else echo No; fi


If it doesn't, we will need to build non-AVX images manually from
source code:

.. code-block:: bash

   cd ~
   git clone https://github.com/PaddlePaddle/Paddle.git
   cd Paddle
   docker build --build-arg WITH_AVX=OFF -t paddle:cpu-noavx -f paddle/scripts/docker/Dockerfile .
   docker build --build-arg WITH_AVX=OFF -t paddle:gpu-noavx -f paddle/scripts/docker/Dockerfile.gpu .


114 115 116
Development Using Docker
------------------------

D
dayhaha 已提交
117
Developers can work on PaddlePaddle using Docker.  This allows
118 119 120
developers to work on different platforms -- Linux, Mac OS X, and
Windows -- in a consistent way.

王益 已提交
121
1. Build the Development Environment as a Docker Image
122 123 124

   .. code-block:: bash

王益 已提交
125 126 127
      git clone --recursive https://github.com/PaddlePaddle/Paddle
      cd Paddle
      docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile .
D
dayhaha 已提交
128 129


王益 已提交
130 131 132
   Note that by default :code:`docker build` wouldn't import source
   tree into the image and build it.  If we want to do that, we need
   to set a build arg:
133 134 135

   .. code-block:: bash

王益 已提交
136
      docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile --build-arg BUILD_AND_INSTALL=ON .
137 138


王益 已提交
139
2. Run the Development Environment
140

王益 已提交
141 142 143
   Once we got the image :code:`paddle:dev`, we can use it to develop
   Paddle by mounting the local source code tree into a container that
   runs the image:
144 145

   .. code-block:: bash
王益 已提交
146

L
liaogang 已提交
147
      docker run -d -p 2202:22 -p 8888:8888 -v $PWD:/paddle paddle:dev
148

王益 已提交
149 150 151
   This runs a container of the development environment Docker image
   with the local source tree mounted to :code:`/paddle` of the
   container.
152

王益 已提交
153 154 155 156
   Note that the default entry-point of :code:`paddle:dev` is
   :code:`sshd`, and above :code:`docker run` commands actually starts
   an SSHD server listening on port 2202.  This allows us to log into
   this container with:
157

王益 已提交
158
   .. code-block:: bash
王益 已提交
159

王益 已提交
160
      ssh root@localhost -p 2202
王益 已提交
161 162 163

   Usually, I run above commands on my Mac.  I can also run them on a
   GPU server :code:`xxx.yyy.zzz.www` and ssh from my Mac to it:
164 165

   .. code-block:: bash
王益 已提交
166

王益 已提交
167
      my-mac$ ssh root@xxx.yyy.zzz.www -p 2202
168

王益 已提交
169
3. Build and Install Using the Development Environment
170

王益 已提交
171 172 173
   Once I am in the container, I can use
   :code:`paddle/scripts/docker/build.sh` to build, install, and test
   Paddle:
174 175

   .. code-block:: bash
王益 已提交
176

王益 已提交
177
      /paddle/paddle/scripts/docker/build.sh
178

王益 已提交
179 180 181 182
   This builds everything about Paddle in :code:`/paddle/build`.  And
   we can run unit tests there:

   .. code-block:: bash
王益 已提交
183

王益 已提交
184 185
      cd /paddle/build
      ctest
186

187 188 189 190 191 192 193 194 195 196

Documentation
-------------

Paddle Docker images include an HTML version of C++ source code
generated using `woboq code browser
<https://github.com/woboq/woboq_codebrowser>`_.  This makes it easy
for users to browse and understand the C++ source code.

As long as we give the Paddle Docker container a name, we can run an
D
dayhaha 已提交
197
additional Nginx Docker container to serve the volume from the Paddle
198 199 200 201
container:

.. code-block:: bash

202
   docker run -d --name paddle-cpu-doc paddle:0.10.0rc1-cpu
203 204 205 206 207
   docker run -d --volumes-from paddle-cpu-doc -p 8088:80 nginx


Then we can direct our Web browser to the HTML version of source code
at http://localhost:8088/paddle/