docker_install_en.rst 7.6 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

Y
yi.wu 已提交
15 16
For each version of PaddlePaddle, we release 2 types of Docker images: development
image and production image. Production image includes CPU-only version and a CUDA
Y
update  
yi.wu 已提交
17 18 19 20
GPU version and their no-AVX versions. We put the docker images on
`dockerhub.com <https://hub.docker.com/r/paddledev/paddle/>`_. You can find the
latest versions under "tags" tab at dockerhub.com.
1. development image :code:`paddlepaddle/paddle:<version>-dev`
21

Y
yi.wu 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    This image has packed related develop tools and runtime environment. Users and
    developers can use this image instead of their own local computer to accomplish
    development, build, releasing, document writing etc. While different version of
    paddle may depends on different version of libraries and tools, if you want to
    setup a local environment, you must pay attention to the versions.
    The development image contains:
    - gcc/clang
    - nvcc
    - Python
    - sphinx
    - woboq
    - sshd
    Many developers use servers with GPUs, they can use ssh to login to the server
    and run :code:`docker exec` to enter the docker container and start their work.
    Also they can start a development docker image with SSHD service, so they can login to
    the container and start work.
38

Y
yi.wu 已提交
39
    To run the CPU-only image as an interactive container:
40

Y
yi.wu 已提交
41
    .. code-block:: bash
42

Y
yi.wu 已提交
43
        docker run -it --rm paddledev/paddle:<version> /bin/bash
44

Y
yi.wu 已提交
45
    or, we can run it as a daemon container
46

Y
yi.wu 已提交
47
    .. code-block:: bash
48

Y
yi.wu 已提交
49
        docker run -d -p 2202:22 -p 8888:8888 paddledev/paddle:<version>
50

Y
yi.wu 已提交
51
    and SSH to this container using password :code:`root`:
52

Y
yi.wu 已提交
53
    .. code-block:: bash
54

Y
yi.wu 已提交
55
        ssh -p 2202 root@localhost
56

Y
yi.wu 已提交
57 58 59 60 61
    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.
L
liaogang 已提交
62 63


Y
yi.wu 已提交
64 65 66 67 68
2. Production images, this image might have multiple variants:
    - GPU/AVX::code:`paddlepaddle/paddle:<version>-gpu`
    - GPU/no-AVX::code:`paddlepaddle/paddle:<version>-gpu-noavx`
    - CPU/AVX::code:`paddlepaddle/paddle:<version>`
    - CPU/no-AVX::code:`paddlepaddle/paddle:<version>-noavx`
L
liaogang 已提交
69

Y
yi.wu 已提交
70 71 72 73
    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:
L
liaogang 已提交
74

Y
yi.wu 已提交
75
    .. code-block:: bash
76

Y
yi.wu 已提交
77 78 79 80 81
       if cat /proc/cpuinfo | grep -i avx; then echo Yes; else echo No; fi


       If it doesn't, we will use the non-AVX images.

L
liaogang 已提交
82 83 84 85 86 87 88 89 90
    Above methods work with the GPU image too -- just please don't forget
    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).
Y
yi.wu 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104

    .. 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:<version>-gpu


3. Use production image to release you AI application
    Suppose that we have a simple application program in :code:`a.py`, we can test and run it using the production image:

    ```bash
    docker run -it -v $PWD:/work paddle /work/a.py
    ```
105

Y
yi.wu 已提交
106
    But this works only if all dependencies of :code:`a.py` are in the production image. If this is not the case, we need to build a new Docker image from the production image and with more dependencies installs.
107 108 109 110 111 112 113 114 115


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.

Y
yi.wu 已提交
116
PaddlePaddle Book is an interactive Jupyter Notebook for users and developers.
117 118 119
We already exposed port 8888 for this book. If you want to
dig deeper into deep learning, PaddlePaddle Book definitely is your best choice.

Y
yi.wu 已提交
120
We provide a packaged book image, simply issue the command:
121 122

.. code-block:: bash
Y
yi.wu 已提交
123

Y
update  
yi.wu 已提交
124
    docker run -p 8888:8888 paddlepaddle/book
125 126

Then, you would back and paste the address into the local browser:
Y
yi.wu 已提交
127

128 129 130 131 132 133
.. code-block:: text

    http://localhost:8888/

That's all. Enjoy your journey!

134 135 136
Development Using Docker
------------------------

D
dayhaha 已提交
137
Developers can work on PaddlePaddle using Docker.  This allows
138 139 140
developers to work on different platforms -- Linux, Mac OS X, and
Windows -- in a consistent way.

Y
yi.wu 已提交
141
1. Build the Development Docker Image
142 143 144

   .. code-block:: bash

王益 已提交
145 146
      git clone --recursive https://github.com/PaddlePaddle/Paddle
      cd Paddle
Y
yi.wu 已提交
147
      docker build -t paddle:dev .
D
dayhaha 已提交
148

王益 已提交
149
   Note that by default :code:`docker build` wouldn't import source
Y
update  
yi.wu 已提交
150 151
   tree into the image and build it.  If we want to do that, we need docker the
   development docker image and then run the following command:
152 153 154

   .. code-block:: bash

Y
yi.wu 已提交
155
      docker run -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_AVX=ON" -e "TEST=OFF" paddle:dev
156 157


王益 已提交
158
2. Run the Development Environment
159

王益 已提交
160 161 162
   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:
163 164

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

Y
yi.wu 已提交
166
      docker run -d -p 2202:22 -p 8888:8888 -v $PWD:/paddle paddle:dev sshd
167

王益 已提交
168 169 170
   This runs a container of the development environment Docker image
   with the local source tree mounted to :code:`/paddle` of the
   container.
171

Y
yi.wu 已提交
172
   The above :code:`docker run` commands actually starts
王益 已提交
173 174
   an SSHD server listening on port 2202.  This allows us to log into
   this container with:
175

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

王益 已提交
178
      ssh root@localhost -p 2202
王益 已提交
179 180 181

   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:
182 183

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

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

王益 已提交
187
3. Build and Install Using the Development Environment
188

王益 已提交
189 190 191
   Once I am in the container, I can use
   :code:`paddle/scripts/docker/build.sh` to build, install, and test
   Paddle:
192 193

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

王益 已提交
195
      /paddle/paddle/scripts/docker/build.sh
196

王益 已提交
197 198 199 200
   This builds everything about Paddle in :code:`/paddle/build`.  And
   we can run unit tests there:

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

王益 已提交
202 203
      cd /paddle/build
      ctest
204

205 206 207 208 209 210 211 212 213 214

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 已提交
215
additional Nginx Docker container to serve the volume from the Paddle
216 217 218 219
container:

.. code-block:: bash

Y
yi.wu 已提交
220
   docker run -d --name paddle-cpu-doc paddle:<version>
221 222 223 224 225
   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/