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


12 13 14
Development Using Docker
------------------------

D
dayhaha 已提交
15
Developers can work on PaddlePaddle using Docker.  This allows
16 17 18 19 20 21 22 23 24
developers to work on different platforms -- Linux, Mac OS X, and
Windows -- in a consistent way.

The general development workflow with Docker and Bazel is as follows:

1. Get the source code of Paddle:

   .. code-block:: bash

D
dayhaha 已提交
25
      git clone --recursive https://github.com/PaddlePaddle/Paddle.git
26 27 28 29

   
   Here **git clone --recursive is required** as we have a submodule `warp-ctc <https://github.com/baidu-research/warp-ctc>`_.

D
dayhaha 已提交
30 31 32 33 34 35 36 37
   If you have used :code:`git clone https://github.com/PaddlePaddle/Paddle` and find that the directory :code:`warp-ctc` is
   empty, please use the following command to get the submodule.

   .. code-block:: bash

      git submodule update --init --recursive


38 39 40 41 42 43 44 45 46
2. Build a development Docker image :code:`paddle:dev` from the source
   code.  This image contains all the development tools and
   dependencies of PaddlePaddle.

   .. code-block:: bash

      cd paddle
      docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile .

Y
yangwenbo02 已提交
47
   Sometimes docker build might suffer from a slow network connection to the official Ubuntu apt-source servers. In such case, we can specify an apt-source mirror server that is geologically nearer to us. In the following example, we specified an apt-source server that responds fast in China.You can specify the UBUNTU MIRROR with :code:`--build-arg UBUNTU_MIRROR` like the example below.
48 49 50

   .. code-block:: bash

Y
yangwenbo02 已提交
51 52 53 54
      docker build \
       --build-arg UBUNTU_MIRROR="http://mirrors.163.com" \
       -t paddle:dev \
       -f paddle/scripts/docker/Dockerfile .
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

3. Run the image as a container and mounting local source code
   directory into the container.  This allows us to change the code on
   the host and build it within the container.

   .. code-block:: bash

      docker run       \
       -d              \
       --name paddle   \
       -p 2022:22      \
       -v $PWD:/paddle \
       -v $HOME/.cache/bazel:/root/.cache/bazel \
       paddle:dev

   where :code:`-d` makes the container running in background,
   :code:`--name paddle` allows us to run a nginx container to serve
   documents in this container, :code:`-p 2022:22` allows us to SSH
   into this container, :code:`-v $PWD:/paddle` shares the source code
   on the host with the container, :code:`-v
   $HOME/.cache/bazel:/root/.cache/bazel` shares Bazel cache on the
   host with the container.

4. SSH into the container:

   .. code-block:: bash

      ssh root@localhost -p 2022

5. We can edit the source code in the container or on this host.  Then
   we can build using cmake

   .. code-block:: bash

      cd /paddle # where paddle source code has been mounted into the container
      mkdir -p build
      cd build
      cmake -DWITH_TESTING=ON ..
      make -j `nproc`
      CTEST_OUTPUT_ON_FAILURE=1 ctest

   or Bazel in the container:

   .. code-block:: bash

      cd /paddle
      bazel test ...


Y
Yi Wang 已提交
105 106
CPU-only and GPU Images
-----------------------
107

Y
Yi Wang 已提交
108 109 110 111
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 runs the following commands:
112

L
liaogang 已提交
113
.. code-block:: bash
114

115 116
   docker build -t paddle:cpu -f paddle/scripts/docker/Dockerfile .
   docker build -t paddle:gpu -f paddle/scripts/docker/Dockerfile.gpu .
Y
Yi Wang 已提交
117

Y
Yi Wang 已提交
118

Y
Yi Wang 已提交
119
To run the CPU-only image as an interactive container:
Y
Yi Wang 已提交
120 121 122

.. code-block:: bash

Y
Yi Wang 已提交
123
    docker run -it --rm paddledev/paddle:cpu-latest /bin/bash
124

Y
Yi Wang 已提交
125
or, we can run it as a daemon container
126

Y
Yi Wang 已提交
127
.. code-block:: bash
128

Y
Yi Wang 已提交
129
    docker run -d -p 2202:22 paddledev/paddle:cpu-latest
130

Y
Yi Wang 已提交
131
and SSH to this container using password :code:`root`:
132

Y
Yi Wang 已提交
133
.. code-block:: bash
134

Y
Yi Wang 已提交
135
    ssh -p 2202 root@localhost
136

Y
Yi Wang 已提交
137 138 139 140 141
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.
142 143


Y
Yi Wang 已提交
144 145
Above methods work with the GPU image too -- just please don't forget
to install CUDA driver and let Docker knows about it:
146

Y
Yi Wang 已提交
147
.. code-block:: bash
148

Y
Yi Wang 已提交
149 150 151
    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:gpu-latest
152 153


Y
Yi Wang 已提交
154 155
Non-AVX Images
--------------
156

Y
Yi Wang 已提交
157 158 159 160
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:
161

Y
Yi Wang 已提交
162
.. code-block:: bash
163

Y
Yi Wang 已提交
164 165
   if cat /proc/cpuinfo | grep -i avx; then echo Yes; else echo No; fi

166

Y
Yi Wang 已提交
167 168
If it doesn't, we will need to build non-AVX images manually from
source code:
169

Y
Yi Wang 已提交
170
.. code-block:: bash
171

Y
Yi Wang 已提交
172
   cd ~
D
dayhaha 已提交
173
   git clone https://github.com/PaddlePaddle/Paddle.git
Y
Yi Wang 已提交
174
   cd Paddle
L
Liu Yiqun 已提交
175
   git submodule update --init --recursive
Y
Yi Wang 已提交
176 177
   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 .
178 179 180 181 182 183 184 185 186 187 188


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 已提交
189
additional Nginx Docker container to serve the volume from the Paddle
190 191 192 193 194 195 196 197 198 199
container:

.. code-block:: bash

   docker run -d --name paddle-cpu-doc paddle:cpu
   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/