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


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

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

王益 已提交
19
1. Build the Development Environment as a Docker Image
20 21 22

   .. code-block:: bash

王益 已提交
23 24 25
      git clone --recursive https://github.com/PaddlePaddle/Paddle
      cd Paddle
      docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile .
D
dayhaha 已提交
26 27


王益 已提交
28 29 30
   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:
31 32 33

   .. code-block:: bash

王益 已提交
34
      docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile --build-arg BUILD_AND_INSTALL=ON .
35 36


王益 已提交
37
2. Run the Development Environment
38

王益 已提交
39 40 41
   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:
42 43

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

王益 已提交
45
      docker run -d -p 2202:22 -v $PWD:/paddle paddle:dev
46

王益 已提交
47 48 49
   This runs a container of the development environment Docker image
   with the local source tree mounted to :code:`/paddle` of the
   container.
50

王益 已提交
51 52 53 54
   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:
55

王益 已提交
56
   .. code-block:: bash
王益 已提交
57

王益 已提交
58
      ssh root@localhost -p 2202
王益 已提交
59 60 61

   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:
62 63

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

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

王益 已提交
67
3. Build and Install Using the Development Environment
68

王益 已提交
69 70 71
   Once I am in the container, I can use
   :code:`paddle/scripts/docker/build.sh` to build, install, and test
   Paddle:
72 73

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

王益 已提交
75
      /paddle/paddle/scripts/docker/build.sh
76

王益 已提交
77 78 79 80
   This builds everything about Paddle in :code:`/paddle/build`.  And
   we can run unit tests there:

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

王益 已提交
82 83
      cd /paddle/build
      ctest
84 85


Y
Yi Wang 已提交
86 87
CPU-only and GPU Images
-----------------------
88

Y
Yi Wang 已提交
89 90 91 92
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:
93

L
liaogang 已提交
94
.. code-block:: bash
95

96 97
   docker build -t paddle:cpu -f paddle/scripts/docker/Dockerfile .
   docker build -t paddle:gpu -f paddle/scripts/docker/Dockerfile.gpu .
Y
Yi Wang 已提交
98

Y
Yi Wang 已提交
99

Y
Yi Wang 已提交
100
To run the CPU-only image as an interactive container:
Y
Yi Wang 已提交
101 102 103

.. code-block:: bash

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

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

Y
Yi Wang 已提交
108
.. code-block:: bash
109

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

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

Y
Yi Wang 已提交
114
.. code-block:: bash
115

Y
Yi Wang 已提交
116
    ssh -p 2202 root@localhost
117

Y
Yi Wang 已提交
118 119 120 121 122
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.
123 124


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

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

Y
Yi Wang 已提交
130 131 132
    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
133 134


Y
Yi Wang 已提交
135 136
Non-AVX Images
--------------
137

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

Y
Yi Wang 已提交
143
.. code-block:: bash
144

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

147

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

Y
Yi Wang 已提交
151
.. code-block:: bash
152

Y
Yi Wang 已提交
153
   cd ~
D
dayhaha 已提交
154
   git clone https://github.com/PaddlePaddle/Paddle.git
Y
Yi Wang 已提交
155 156 157
   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 .
158 159 160 161 162 163 164 165 166 167 168


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 已提交
169
additional Nginx Docker container to serve the volume from the Paddle
170 171 172 173 174 175 176 177 178 179
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/