mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-17 20:51:21 +08:00
doc: Update dockerfile.md #120 61c3a6e528
This commit is contained in:
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
@ -42,7 +42,7 @@
|
||||
<p>这是 <a href="https://docs.docker.com/engine/reference/builder/">Dockerfile</a> 的快速参考备忘单。包含用户可以在命令行上调用以组装镜像的所有命令。</p>
|
||||
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
|
||||
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
|
||||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#参考">参考</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#继承">继承</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#继承-1">继承</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#变量-env">变量 ENV</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#初始化">初始化</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#onbuild">Onbuild</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#在严格的-shell-中运行命令">在严格的 shell 中运行命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#命令-cmd">命令 CMD</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#入口点-entrypoint">入口点 ENTRYPOINT</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#元数据-label">元数据 LABEL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#arg">ARG</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#dockerignore-文件">.dockerignore 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#主要命令">主要命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-镜像多阶段构建">Docker 镜像多阶段构建</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#也可以看看">也可以看看</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="参考"><a aria-hidden="true" tabindex="-1" href="#参考"><span class="icon icon-link"></span></a>参考</h2><div class="wrap-body">
|
||||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#参考">参考</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#继承">继承</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#继承-1">继承</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#变量-env">变量 ENV</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#初始化">初始化</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#onbuild">Onbuild</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#在严格的-shell-中运行命令">在严格的 shell 中运行命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#命令-cmd">命令 CMD</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#入口点-entrypoint">入口点 ENTRYPOINT</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#元数据-label">元数据 LABEL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#arg">ARG</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#dockerignore-文件">.dockerignore 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#主要命令">主要命令</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#dockerfile-示例">Dockerfile 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#服务静态网站的最小-docker-镜像">服务静态网站的最小 Docker 镜像</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-镜像多阶段构建">Docker 镜像多阶段构建</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#也可以看看">也可以看看</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="参考"><a aria-hidden="true" tabindex="-1" href="#参考"><span class="icon icon-link"></span></a>参考</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="继承"><a aria-hidden="true" tabindex="-1" href="#继承"><span class="icon icon-link"></span></a>继承</h3><div class="wrap-body">
|
||||
<p>默认 <code>Dockerfile</code> 位于上下文的根目录中。</p>
|
||||
<ul>
|
||||
@ -251,8 +251,22 @@
|
||||
|
||||
<table class="auto-wrap"><thead><tr><th align="left">命令</th><th>说明</th></tr></thead><tbody><tr><td align="left"><code>FROM image</code></td><td>构建的基础镜像</td></tr><tr><td align="left"><del><code>MAINTAINER email</code></del></td><td>(已弃用)维护者的名字</td></tr><tr><td align="left"><code>COPY [--chown=<user>:<group>] <src>... <dest></code></td><td>将上下文中的路径复制到位置 <code>dest</code> 的容器中</td></tr><tr><td align="left"><code>ADD [--chown=<user>:<group>] <src>... <dest></code></td><td>与 <code>COPY</code> 相同,但解压缩存档并接受 http url。</td></tr><tr><td align="left"><code>RUN <command></code></td><td>在容器内运行任意命令。</td></tr><tr><td align="left"><code>USER <user>[:<group>]</code></td><td>设置默认用户名。</td></tr><tr><td align="left"><code>WORKDIR /path/to/workdir</code></td><td>设置默认工作目录。</td></tr><tr><td align="left"><code>CMD command param1 param2</code></td><td>设置默认命令</td></tr><tr><td align="left"><code>ENV <key>=<value> ...</code></td><td>设置环境变量</td></tr><tr><td align="left"><code>EXPOSE <port> [<port>/<protocol>...]</code></td><td>运行时侦听指定的网络端口</td></tr></tbody></table>
|
||||
<!--rehype:class=auto-wrap-->
|
||||
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="docker-镜像多阶段构建"><a aria-hidden="true" tabindex="-1" href="#docker-镜像多阶段构建"><span class="icon icon-link"></span></a>Docker 镜像多阶段构建</h3><div class="wrap-body">
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="dockerfile-示例"><a aria-hidden="true" tabindex="-1" href="#dockerfile-示例"><span class="icon icon-link"></span></a>Dockerfile 示例</h2><div class="wrap-body">
|
||||
<!--rehype:body-class=cols-2-->
|
||||
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="服务静态网站的最小-docker-镜像"><a aria-hidden="true" tabindex="-1" href="#服务静态网站的最小-docker-镜像"><span class="icon icon-link"></span></a>服务静态网站的最小 Docker 镜像</h3><div class="wrap-body">
|
||||
<pre class="language-dockerfile"><code class="language-dockerfile code-highlight"><span class="code-line"><span class="token instruction"><span class="token keyword">FROM</span> lipanski/docker-static-website:latest</span>
|
||||
</span><span class="code-line"><span class="token comment"># 使用 .dockerignore 文件来控制图像中的内容!</span>
|
||||
</span><span class="code-line"><span class="token comment"># 复制当前目录内容,到容器中</span>
|
||||
</span><span class="code-line"><span class="token instruction"><span class="token keyword">COPY</span> ./ .</span>
|
||||
</span></code></pre>
|
||||
<p>这会产生一个 <strong><code>154KB +</code></strong> 的单层镜像。 如果您需要以不同的方式配置 <code>httpd</code>,您可以覆盖 CMD 行:</p>
|
||||
<pre class="language-dockerfile"><code class="language-dockerfile code-highlight"><span class="code-line"><span class="token instruction"><span class="token keyword">FROM</span> lipanski/docker-static-website:latest</span>
|
||||
</span><span class="code-line"><span class="token instruction"><span class="token keyword">COPY</span> . .</span>
|
||||
</span><span class="code-line">
|
||||
</span><span class="code-line"><span class="token instruction"><span class="token keyword">CMD</span> [<span class="token string">"/busybox"</span>,<span class="token string">"httpd"</span>,<span class="token string">"-f"</span>,<span class="token string">"-v"</span>,<span class="token string">"-p"</span>,<span class="token string">"3000"</span>,<span class="token string">"-c"</span>,<span class="token string">"httpd.conf"</span>]</span>
|
||||
</span></code></pre>
|
||||
<p>缩小镜像过程<a href="https://lipanski.com/posts/smallest-docker-image-static-website">查看原文</a>,镜像 <a href="https://github.com/lipanski/docker-static-website">Dockerfile 源码</a>。</p>
|
||||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-镜像多阶段构建"><a aria-hidden="true" tabindex="-1" href="#docker-镜像多阶段构建"><span class="icon icon-link"></span></a>Docker 镜像多阶段构建</h3><div class="wrap-body">
|
||||
<pre class="wrap-text "><code class="language-dockerfile code-highlight"><span class="code-line"><span class="token instruction"><span class="token keyword">FROM</span> golang:alpine <span class="token keyword">as</span> builder</span>
|
||||
</span><span class="code-line"><span class="token instruction"><span class="token keyword">RUN</span> apk --no-cache add git</span>
|
||||
</span><span class="code-line"><span class="token instruction"><span class="token keyword">WORKDIR</span> /go/src/github.com/go/helloworld/</span>
|
||||
|
@ -562,7 +562,7 @@
|
||||
<!--rehype:class=home-card&style=margin:1.2rem 0;display: flex;justify-content: center;-->
|
||||
<p>如果你有资源,可以很方便部署 web 版,这非常简单,只需要克隆 gh-pages 分支代码到你的静态服务就可以了,还可以使用 <a href="https://hub.docker.com/r/wcjiang/reference">docker</a> 快捷部署 web 版。</p>
|
||||
|
||||
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang. Updated on 2022/11/17 15:32:46</footer></footer><script>
|
||||
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang. Updated on 2022/11/17 15:38:38</footer></footer><script>
|
||||
if(('onhashchange' in window) && ((typeof document.documentMode==='undefined') || document.documentMode==8)) {
|
||||
window.onhashchange = function () {
|
||||
anchorPoint()
|
||||
|
Reference in New Issue
Block a user