黄督师 發表於 2023-7-13 15:38:00

Debian Docker 安装

<h1>Debian Docker 安装</h1>
<p>Docker 支持以下的 Debian 版本:</p>
<ul>
<li>Buster 10</li>
<li>Stretch 9 (stable) / Raspbian Stretch</li>
</ul>
<p>Docker Engine-Community 在 x86_64(或 amd64 )armhf,和 arm64 体系结构上受支持。</p>
<hr>
<h2>使用官方安装脚本自动安装</h2>
<p>安装命令如下:</p>
<pre class="prettyprint prettyprinted"><span class="pln"> curl <span class="pun">-<span class="pln">fsSL https<span class="pun">:<span class="com">//get.docker.com -o get-docker.sh<span class="pln">
sudo sh <span class="kwd">get<span class="pun">-<span class="pln">docker<span class="pun">.<span class="pln">sh</span></span></span></span></span></span></span></span></span></span></span></pre>
<hr>
<h2>手动安装</h2>
<h3>卸载旧版本</h3>
<p>Docker 的旧版本被称为 docker,docker.io 或 docker-engine,如果已安装,请卸载它们:</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> remove docker docker<span class="pun">-<span class="pln">engine docker<span class="pun">.<span class="pln">io containerd runc</span></span></span></span></span></span></span></span></pre>
<h3>安装 Docker Engine-Community</h3>
<h3>使用 Docker 仓库进行安装</h3>
<p>在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker。</p>
<p>Raspbian 用户不能使用此方法!</p>
<p>对于 Raspbian,尚不支持使用仓库进行安装。您必须改为使用 shell 脚本方式。</p>
<h3>设置仓库</h3>
<p>更新 apt 包索引。</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> update</span></span></span></span></pre>
<p>安装 apt 依赖包,用于通过 HTTPS 来获取仓库。</p>
<div class="example">
<div class="example_code">$&nbsp;sudo&nbsp;apt-get install&nbsp;\<br>&nbsp; &nbsp; apt-transport-https \<br>&nbsp; &nbsp; ca-certificates \<br>&nbsp; &nbsp; curl \<br>&nbsp; &nbsp; gnupg2 \<br>&nbsp; &nbsp; software-properties-common</div>


</div>
<p>添加 Docker 的官方 GPG 密钥:</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ curl <span class="pun">-<span class="pln">fsSL https<span class="pun">:<span class="com">//mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -</span></span></span></span></span></pre>
<p>9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥。</p>
<div class="example">
<div class="example_code">$&nbsp;sudo&nbsp;apt-key&nbsp;fingerprint 0EBFCD88<br><br>pub &nbsp; 4096R/0EBFCD88&nbsp;2017-02-22<br>&nbsp; &nbsp; &nbsp; Key fingerprint = 9DC8&nbsp;5822&nbsp;9FC7 DD38 854A &nbsp;E2D8 8D81 803C 0EBF CD88<br>uid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Docker Release&nbsp;(CE deb)&nbsp;&lt;docker@docker.com&gt;<br>sub &nbsp; 4096R/F273FCD8&nbsp;2017-02-22</div>


</div>
<p>使用以下指令设置稳定版仓库:</p>
<div class="example">
<div class="example_code">$&nbsp;sudo&nbsp;add-apt-repository \<br>&nbsp; &nbsp;"deb https://mirrors.ustc.edu.cn/docker-ce/linux/debian&nbsp;\<br>&nbsp;&nbsp;$(lsb_release -cs)&nbsp;\<br>&nbsp; stable"</div>


</div>
<h3>安装 Docker Engine-Community</h3>
<p>更新 apt 包索引:</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> update</span></span></span></span></pre>
<p>安装最新版本的 Docker Engine-Community 和 containerd ,或者转到下一步安装特定版本:</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> install docker<span class="pun">-<span class="pln">ce docker<span class="pun">-<span class="pln">ce<span class="pun">-<span class="pln">cli containerd<span class="pun">.<span class="pln">io</span></span></span></span></span></span></span></span></span></span></span></span></pre>
<p>要安装特定版本的 Docker Engine-Community,请在仓库中列出可用版本,然后选择一种安装。列出您的仓库中可用的版本:</p>
<div class="example">
<div class="example_code">$&nbsp;apt-cache&nbsp;madison docker-ce<br><br>&nbsp; docker-ce&nbsp;|&nbsp;5:18.09.1~3-0~debian-stretch&nbsp;|&nbsp;https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch/stable amd64 Packages<br>&nbsp; docker-ce&nbsp;|&nbsp;5:18.09.0~3-0~debian-stretch&nbsp;|&nbsp;https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch/stable amd64 Packages<br>&nbsp; docker-ce&nbsp;|&nbsp;18.06.1~ce~3-0~debian &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp;https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch/stable amd64 Packages<br>&nbsp; docker-ce&nbsp;|&nbsp;18.06.0~ce~3-0~debian &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp;https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch/stable amd64 Packages<br>&nbsp; ...</div>


</div>
<p>使用第二列中的版本字符串安装特定版本,例如 5:18.09.1~3-0~debian-stretch 。</p>
<pre class="prettyprint prettyprinted"><span class="pln">$ sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> install docker<span class="pun">-<span class="pln">ce<span class="pun">=&lt;<span class="pln">VERSION_STRING<span class="pun">&gt;<span class="pln"> docker<span class="pun">-<span class="pln">ce<span class="pun">-<span class="pln">cli<span class="pun">=&lt;<span class="pln">VERSION_STRING<span class="pun">&gt;<span class="pln"> containerd<span class="pun">.<span class="pln">io</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
<p>测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:</p>
<div class="example">
<div class="example_code">$&nbsp;sudo&nbsp;docker run hello-world<br><br>Unable to&nbsp;find&nbsp;image&nbsp;'hello-world:latest'&nbsp;locally<br>latest: Pulling from library/hello-world<br>1b930d010525: Pull&nbsp;complete&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f<br>Status: Downloaded newer image&nbsp;for&nbsp;hello-world:latest<br><br><br>Hello from Docker!<br>This message shows that your installation appears to be working correctly.<br><br><br>To generate this message, Docker took the following steps:<br>&nbsp;1. The Docker client contacted the Docker daemon.<br>&nbsp;2. The Docker daemon pulled the&nbsp;"hello-world"&nbsp;image from the Docker Hub.<br>&nbsp; &nbsp;&nbsp;(amd64)<br>&nbsp;3. The Docker daemon created a new container from that image&nbsp;which&nbsp;runs the<br>&nbsp; &nbsp; executable that produces the output you are currently reading.<br>&nbsp;4. The Docker daemon streamed that output to the Docker client,&nbsp;which&nbsp;sent it<br>&nbsp; &nbsp; to your terminal.<br><br><br>To try something&nbsp;more&nbsp;ambitious, you can run an Ubuntu container with:<br>&nbsp;$ docker run&nbsp;-it&nbsp;ubuntu&nbsp;bash<br><br><br>Share images, automate workflows, and&nbsp;more&nbsp;with a&nbsp;free&nbsp;Docker ID:<br>&nbsp;https://hub.docker.com/<br><br><br>For&nbsp;more&nbsp;examples and ideas, visit:<br>&nbsp;https://docs.docker.com/get-started/</div>


</div>
<h3>卸载 docker</h3>
<p>删除安装包:</p>
<pre class="prettyprint prettyprinted"><span class="pln">sudo apt<span class="pun">-<span class="kwd">get<span class="pln"> purge docker<span class="pun">-<span class="pln">ce</span></span></span></span></span></span></pre>
<p>删除镜像、容器、配置文件等内容:</p>
<pre class="prettyprint prettyprinted"><span class="pln">sudo rm <span class="pun">-<span class="pln">rf <span class="pun">/<span class="kwd">var<span class="pun">/<span class="pln">lib<span class="pun">/<span class="pln">docker</span></span></span></span></span></span></span></span></span></pre>
<div><span class="pln">&nbsp;转载</span></div>
<div><span class="pln">https://m.runoob.com/docker/debian-docker-install.html</span></div><br><br>
来源:https://www.cnblogs.com/lovleo/p/17551095.html
頁: [1]
查看完整版本: Debian Docker 安装