如何在 Debian 9 上安装和使用 Docker
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 是一个容器化平台,允许您快速构建,测试和部署应用程序,作为便携式,自给自足的容器,几乎可以在任何地方运行。</p><p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 是容器技术的事实上的标准,它是 DevOps 工程师及其持续集成和交付管道的必备工具。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">在本教程中,我们将指导您完成在 Debian 9 机器上安装 Docker 的过程,并探索基本的 Docker 概念和命令。</p>
<h2 id="先决条件" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">先决条件</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">在继续本教程之前,请确保以具有 sudo 权限的用户身份登录。本教程中的所有命令都应以非 root 用户身份运行。</p>
<h2 id="在-debian-上安装-docker" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">在 Debian 上安装 Docker</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">以下步骤描述了如何从 Docker 的存储库安装最新的稳定版本的过程。</p>
<ol style="list-style: none; margin: 0 0.5rem 1rem; padding: 0; color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; counter-reset: listCounter 0; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<li>
<p>将已安装的软件包更新到最新版本:</p>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo apt update
sudo apt upgrade</code></pre>
</div>
<ol>
<li>安装通过 HTTPS 添加新存储库所需的依赖项:</li>
</ol>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2</code></pre>
</div>
</li>
<li>
<p>使用以下 curl 命令导入存储库的 GPG 密钥:</p>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -</code></pre>
</div>
<p>键入以下内容,将 Docker APT 存储库添加到系统的软件存储库列表中:</p>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo add-apt-repository "deb https://download.docker.com/linux/debian $(lsb_release -cs) stable"</code></pre>
</div>
<blockquote>
<p><code>$(lsb_release -cs)</code> 将返回 Debian 发行版的名称,在本例中,它返回 <code>stretch</code> 。</p>
</blockquote>
</li>
<li>
<p>现在已启用 Docker 存储库,更新 <code>apt</code> 软件包列表并安装最新版本的 Docker CE (Community Edition):</p>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo apt updatesudo apt install docker-ce</code></pre>
</div>
<ol>
<li>安装完成后, Docker 服务将自动启动。您可以输入以下命令进行验证:</li>
</ol>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo systemctl status docker</code></pre>
</div>
<div class="highlight">
<pre class="chroma"><code class="language-output" data-lang="output">● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-07-27 17:02:07 UTC; 1min 14s ago
Docs: https://docs.docker.com
Main PID: 16929 (dockerd)
CGroup: /system.slice/docker.service</code></pre>
</div>
<ol>
<li>在撰写本文时, Debian 9 的当前版本的 Docker 是 <code>18.06.0-ce</code> 。查看 Docker 版本:</li>
</ol>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker -v</code></pre>
</div>
<div class="highlight">
<pre class="chroma"><code class="language-output" data-lang="output">Docker version 18.06.0-ce, build 0ffa825</code></pre>
</div>
<h2 id="在没有-sudo-的情况下执行-docker-命令">在没有 sudo 的情况下执行 Docker 命令</h2>
<p>默认情况下,只有具有管理员权限的用户才能执行 Docker 命令。</p>
<p>如果您希望以非 root 用户身份运行 Docker 命令而不 <code>sudo</code> 需要预先添加,则需要将用户添加到安装 Docker CE 软件包期间创建的 docker 组。您可以输入以下命令:</p>
<div class="highlight">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">sudo usermod -aG docker $USER</code></pre>
</div>
</li>
</ol>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">注销并重新登录,以便刷新组成员身份。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">要验证您是否可以在不添加 <code>sudo</code> 前缀情况下运行 docker 命令,请运行以下命令(它将下载测试镜像),在容器中运行它,打印 “Hello from Docker” 消息并退出:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container run hello-world</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">输出应如下所示:</p>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-hello-world.jpg"></p>
<h2 id="docker-命令行界面" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 命令行界面</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">现在我们已经安装了 Docker ,让我们来看看 docker CLI 的基本语法:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker </code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">如果要列出所有可用的命令,请不带参数运行 <code>docker</code> :</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">如果您需要关于 <code></code> 的更多帮助信息,可以使用如下所示的 <code>--help</code> 开关:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker --help</code></pre>
</div>
<h2 id="docker-镜像" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 镜像</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 镜像由一系列文件系统层组成,这些文件系统层表现为镜像的 Dockerfile 中的指令,构成可执行软件应用程序。镜像是一个不可变的二进制文件,包括应用程序和运行应用程序所需的所有其他依赖项,如库,二进制文件和指令。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">您可以将 Docker 镜像视为 Docker 容器的快照。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker Hub 上提供了大多数 Docker 镜像。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker Hub 是基于云的注册服务,用于将 Docker 镜像保存在公共或私有存储库中。</p>
<h3 id="搜索-docker-镜像" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">搜索 Docker 镜像</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">要从 Docker Hub 注册表中搜索镜像,请使用 <code>search</code> 子命令。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">例如,要搜索 Debian 镜像,您可以键入:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker search debian</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">输出应如下所示:</p>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-search-image.jpg"></p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">正如你可以看到搜索结果打印的表格有 5 列,<code>NAME</code>,<code>DESCRIPTION</code>,<code>STARS</code>,<code>OFFICIAL</code>和<code>AUTOMATED</code>。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">官方镜像是 Docker 与上游合作伙伴共同开发的镜像。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker Hub 上的大多数 Docker 镜像都标有版本号。如果未指定任何标记, Docker 将提取最新镜像。</p>
<h3 id="下载-docker-image" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">下载 Docker Image</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">如果我们想要下载 Debian 镜像的官方版本,我们可以使用 <code>image pull</code> 子命令来完成:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker image pull debian</code></pre>
</div>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-pull-image.jpg"></p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">根据您的 Internet 速度,下载可能需要几秒钟或几分钟。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">由于我们没有指定标签,因此 docker 将提取最新的 Debian 9.5 镜像。如果你想拉取一些以前的 Debian 版本,比如说 Debian 8, 你需要使用 <code>docker image pull debian:8</code></p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">下载镜像后,我们可以通过键入以下内容列出镜像:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker image ls</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">输出看起来像这样:</p>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-list-images.jpg"></p>
<h3 id="删除-docker-镜像" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">删除 Docker 镜像</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">如果由于某种原因您要删除镜像,可以使用 <code>image rm </code> 子命令执行此操作:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker image rm debian</code></pre>
</div>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-remove-image.jpg"></p>
<h2 id="docker-容器" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">Docker 容器</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">镜像的实例称为容器。容器表示单个应用程序,进程或服务的运行时。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">举一个可能不是最合适的类比:如果您是程序员,您可以将 Docker 镜像视为类,将 Docker 容器视为类的一个实例。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">我们可以使用 <code>docker container</code> 子命令启动,停止,删除和管理容器。</p>
<h3 id="启动-docker-容器" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">启动 Docker 容器</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">以下命令将基于 Debian 镜像启动 Docker 容器。如果您没有本地镜像,将首先下载它:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container run debian</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">乍一看,在你看来,根本没有任何事情发生。嗯,那不是真的。 Debian 容器在启动后立即停止,因为它没有长时间运行的进程,我们没有提供任何命令,因此容器启动,运行空命令然后退出。</p>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">选项 <code>-it</code> 允许我们通过命令行与容器进行交互。要启动一个可交互的容器:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container run -it debian /bin/bash</code></pre>
</div>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-output" data-lang="output">root@ee86c8c81b3b:/#</code></pre>
</div>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">正如您在容器启动时从上面的输出中看到的那样,命令提示符已更改,这意味着您现在正在从容器内部工作:</p>
<h3 id="列出-docker-容器" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">列出 Docker 容器</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">要列出活动容器,请键入:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container ls</code></pre>
</div>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-list-containers.jpg"></p>
<blockquote style="margin: 1rem 0; padding: 0 2rem; border-radius: 5px; border: 1px solid rgba(221, 221, 221, 1); color: rgba(128, 128, 128, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 0.87rem; font-style: normal; font-weight: 400; word-spacing: 0; display: block; white-space: normal; position: relative; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 245, 238, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<p>如果您没有任何正在运行的容器,则输出将为空。</p>
</blockquote>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">要查看活动和非活动容器,请使用选项 <code>-a</code> :</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container ls -a</code></pre>
</div>
<p><img src="https://buzheng.org/images/linux/how-to-install-and-use-docker-on-debian-9/docker-list-all-containers.jpg"></p>
<h3 id="删除-docker-容器" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">删除 Docker 容器</h3>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">要删除一个或多个容器,只需复制容器 ID (或 或多个 ID)并将其粘贴到 <code>container rm</code> 子命令之后:</p>
<div class="highlight" style="color: rgba(51, 51, 51, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">
<pre class="chroma"><code class="language-console-bash" data-lang="console-bash">docker container rm c55680af670c</code></pre>
</div>
<h2 id="结论" style="color: rgba(0, 0, 0, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-style: normal; font-weight: 500; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">结论</h2>
<p style="color: rgba(51, 51, 51, 1); text-transform: none; line-height: 1.5; text-indent: 0; letter-spacing: normal; font-family: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif; font-size: 16px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">您已经学习了如何在 Debian 9 机器上安装 Docker 以及如何下载 Docker 镜像和管理 Docker 容器。本教程几乎没有涉及 Docker 生态系统的表面。在我们的下一篇文章中,我们将继续深入探讨 Docker 的其他方面。</p><br><br>
来源:https://www.cnblogs.com/surplus/p/11367567.html
頁:
[1]