docker_install.html 14.0 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 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 46 47 48 49 50 51 52 53 54 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>安装PaddlePaddle的Docker镜像 &mdash; PADDLE  documentation</title>
    
    <link rel="stylesheet" href="../../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="PADDLE  documentation" href="../../index.html" />
    <link rel="up" title="安装Paddle" href="index.html" />
    <link rel="next" title="使用deb包在Ubuntu上安装paddle" href="ubuntu_install.html" />
    <link rel="prev" title="安装Paddle" href="index.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="ubuntu_install.html" title="使用deb包在Ubuntu上安装paddle"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="安装Paddle"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PADDLE  documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >编译与安装</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">安装Paddle</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="paddlepaddledocker">
<h1>安装PaddlePaddle的Docker镜像<a class="headerlink" href="#paddlepaddledocker" title="Permalink to this headline"></a></h1>
<p>PaddlePaddle提供了Docker的使用镜像。PaddlePaddle推荐使用Docker进行Paddle的部署和
运行。Docker是一个基于容器的轻量级虚拟环境。具有和宿主机差不多的运行效率,并提供
了非常方便的二进制分发手段。</p>
<p>下述内容将分为如下几个类别描述。</p>
<ul class="simple">
<li>PaddlePaddle提供的Docker镜像版本</li>
<li>下载和运行Docker镜像</li>
<li>注意事项</li>
</ul>
<div class="section" id="id1">
<h2>PaddlePaddle提供的Docker镜像版本<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<p>我们提供了6个Docker image:</p>
<ul class="simple">
<li>paddledev/paddlepaddle:latest-cpu: Paddle的CPU二进制</li>
<li>paddledev/paddlepaddle:latest-gpu: Paddle的GPU二进制</li>
<li>paddledev/paddlepaddle:latest-cpu-devel: Paddle的CPU二进制,同时包含CPU开发环境和源码</li>
<li>paddledev/paddlepaddle:latest-gpu-devel: Paddle的GPU二进制,同时包含GPU开发环境和源码</li>
<li>paddledev/paddlepaddle:latest-cpu-demo: Paddle的CPU二进制,同时包含CPU开发环境、源码和运行demo的必要依赖</li>
<li>paddledev/paddlepaddle:latest-gpu-demo: Paddle的GPU二进制,同时包含GPU开发环境、源码和运行demo的必要依赖</li>
</ul>
<p>同时,不同的稳定版本,会将latest替换成稳定版本的版本号。</p>
<p>Paddle提供的镜像并不包含任何命令运行,想要运行Paddle,您需要进入镜像运行paddle
程序或者自定义一个含有启动脚本的image。具体请参考注意事项中的
<cite>使用ssh访问paddle镜像</cite></p>
</div>
<div class="section" id="docker">
<h2>下载和运行Docker镜像<a class="headerlink" href="#docker" title="Permalink to this headline"></a></h2>
<p>为了运行PaddlePaddle的docker镜像,您需要在机器中安装好Docker。安装Docker需要您的机器
至少具有3.10以上的linux kernel。安装方法请参考
<a class="reference external" href="https://docs.docker.com/engine/installation/">Docker的官方文档</a> 。如果您使用
mac osx或者是windows机器,请参考
<a class="reference external" href="https://docs.docker.com/engine/installation/mac/">mac osx的安装文档</a>
<a class="reference external" href="https://docs.docker.com/engine/installation/windows/">windows 的安装文档</a></p>
<p>您可以使用 <code class="code docutils literal"><span class="pre">docker</span> <span class="pre">pull</span></code> 命令预先下载镜像,也可以直接执行
<code class="code docutils literal"><span class="pre">docker</span> <span class="pre">run</span></code> 命令运行镜像。执行方法如下:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ docker run -it paddledev/paddlepaddle:latest-cpu
</pre></div>
</div>
<p>即可启动和进入PaddlePaddle的container。如果运行GPU版本的PaddlePaddle,则需要先将
cuda相关的Driver和设备映射进container中,脚本类似于</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ <span class="nb">export</span> <span class="nv">CUDA_SO</span><span class="o">=</span><span class="s2">&quot;</span><span class="k">$(</span><span class="se">\l</span>s /usr/lib64/libcuda* <span class="p">|</span> xargs -I<span class="o">{}</span> <span class="nb">echo</span> <span class="s1">&#39;-v {}:{}&#39;</span><span class="k">)</span><span class="s2"> </span><span class="k">$(</span><span class="se">\l</span>s /usr/lib64/libnvidia* <span class="p">|</span> xargs -I<span class="o">{}</span> <span class="nb">echo</span> <span class="s1">&#39;-v {}:{}&#39;</span><span class="k">)</span><span class="s2">&quot;</span>
$ <span class="nb">export</span> <span class="nv">DEVICES</span><span class="o">=</span><span class="k">$(</span><span class="se">\l</span>s /dev/nvidia* <span class="p">|</span> xargs -I<span class="o">{}</span> <span class="nb">echo</span> <span class="s1">&#39;--device {}:{}&#39;</span><span class="k">)</span>
$ docker run -it paddledev/paddlepaddle:latest-gpu
</pre></div>
</div>
<p>进入Docker container后,运行 <code class="code docutils literal"><span class="pre">paddle</span> <span class="pre">version</span></code> 即可打印出paddle的版本和构建
信息。安装完成的paddle主体包括三个部分, <code class="code docutils literal"><span class="pre">paddle</span></code> 脚本, python的
:code:<a href="#id3"><span class="problematic" id="id4">`</span></a>paddle`包和:code:<a href="#id5"><span class="problematic" id="id6">`</span></a>py_paddle`包。其中:</p>
<ul class="simple">
<li>:code:<a href="#id7"><span class="problematic" id="id8">`</span></a>paddle`脚本和:code:<a href="#id9"><span class="problematic" id="id10">`</span></a>paddle`的python包是paddle的训练主要程序。使用
:code:<a href="#id11"><span class="problematic" id="id12">`</span></a>paddle`脚本可以启动paddle的训练进程和pserver。而:code:<a href="#id13"><span class="problematic" id="id14">`</span></a>paddle`脚本
中的二进制使用了:code:<a href="#id15"><span class="problematic" id="id16">`</span></a>paddle`的python包来做配置文件解析等工作。</li>
<li>python包:code:<a href="#id17"><span class="problematic" id="id18">`</span></a>py_paddle`是一个swig封装的paddle包,用来做预测和简单的定制化
训练。</li>
</ul>
</div>
<div class="section" id="id19">
<h2>注意事项<a class="headerlink" href="#id19" title="Permalink to this headline"></a></h2>
<div class="section" id="id20">
<h3>性能问题<a class="headerlink" href="#id20" title="Permalink to this headline"></a></h3>
<p>由于Docker是基于容器的轻量化虚拟方案,所以在CPU的运算性能上并不会有严重的影响。
而GPU的驱动和设备全部映射到了容器内,所以GPU在运算性能上也不会有严重的影响。</p>
<p>但是如果使用了高性能的网卡,例如RDMA网卡(RoCE 40GbE 或者 IB 56GbE),或者高性能的
以太网卡 (10GbE)。推荐使用将本地网卡,即 &#8220;&#8211;net=host&#8221; 来进行训练。而不使用docker
的网桥来进行网络通信。</p>
</div>
<div class="section" id="id21">
<h3>远程访问问题和二次开发<a class="headerlink" href="#id21" title="Permalink to this headline"></a></h3>
<p>由于Paddle的Docker镜像并不包含任何预定义的运行命令。所以如果想要在后台启用ssh
远程访问,则需要进行一定的二次开发,将ssh装入系统内并开启远程访问。二次开发可以
使用Dockerfile构建一个全新的docker image。需要参考
<a class="reference external" href="https://docs.docker.com/engine/reference/builder/">Dockerfile的文档</a>
<a class="reference external" href="https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/">Dockerfile的最佳实践</a>
两个文档。</p>
<p>简单的含有ssh的Dockerfile如下:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span>FROM paddledev/paddlepaddle

MAINTAINER PaddlePaddle dev team &lt;paddle-dev@baidu.com&gt;

RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo &#39;root:root&#39; | chpasswd

RUN sed -ri &#39;s/^PermitRootLogin\s+.*/PermitRootLogin yes/&#39; /etc/ssh/sshd_config
RUN sed -ri &#39;s/UsePAM yes/#UsePAM yes/g&#39; /etc/ssh/sshd_config

EXPOSE 22

CMD    [&quot;/usr/sbin/sshd&quot;, &quot;-D&quot;]
</pre></div>
</div>
<p>使用该Dockerfile构建出镜像,然后运行这个container即可。相关命令为:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># cd到含有Dockerfile的路径中</span>
$ docker build . -t paddle_ssh
<span class="c1"># 运行这个container,将宿主机的8022端口映射到container的22端口上</span>
$ docker run -d -p 8022:22  --name paddle_ssh_machine paddle_ssh
</pre></div>
</div>
<p>执行如下命令即可以关闭这个container,并且删除container中的数据:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># 关闭container</span>
$ docker stop paddle_ssh_machine
<span class="c1"># 删除container</span>
$ docker rm paddle_ssh_machine
</pre></div>
</div>
<p>如果想要在外部机器访问这个container,即可以使用ssh访问宿主机的8022端口。用户名为
root,密码也是root。命令为:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ ssh -p <span class="m">8022</span> root@YOUR_HOST_MACHINE
</pre></div>
</div>
<p>至此,您就可以远程的使用PaddlePaddle啦。</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">安装PaddlePaddle的Docker镜像</a><ul>
<li><a class="reference internal" href="#id1">PaddlePaddle提供的Docker镜像版本</a></li>
<li><a class="reference internal" href="#docker">下载和运行Docker镜像</a></li>
<li><a class="reference internal" href="#id19">注意事项</a><ul>
<li><a class="reference internal" href="#id20">性能问题</a></li>
<li><a class="reference internal" href="#id21">远程访问问题和二次开发</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">安装Paddle</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="ubuntu_install.html"
                        title="next chapter">使用deb包在Ubuntu上安装paddle</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/build_and_install/install/docker_install.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="ubuntu_install.html" title="使用deb包在Ubuntu上安装paddle"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="安装Paddle"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PADDLE  documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >编译与安装</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >安装Paddle</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2016, PADDLE developers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
    </div>
  </body>
</html>