Docker是一个强大的容器化平台,它彻底改变了软件开发,部署和管理的方式。凭借其隔离应用程序及其依赖项的能力,Docker 提供了增强的可移植性、可扩展性和效率。拥抱 Docker 的强大功能,探索其庞大的生态系统,并为您的项目解锁新的可能性。
在 Debian 12 书虫上安装 Docker(英语:Docker)
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt install apt</span><span class="pun">-</span><span class="pln">transport</span><span class="pun">-</span><span class="pln">https lsb</span><span class="pun">-</span><span class="pln">release ca</span><span class="pun">-</span><span class="pln">certificates curl dirmngr gnupg</span>
此命令将刷新存储库,允许您安装最新版本的软件包。
准备好环境后,让我们继续安装过程。现在我们导入 Docker 存储库的 GPG 密钥:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">fsSL https</span><span class="pun">:</span><span class="com">//download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg</span>
将 Docker 存储库添加到包管理器:
<span class="pln">echo </span><span class="str">"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bookworm stable"</span> <span class="pun">|</span><span class="pln"> sudo tee </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="pln">list</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">docker</span><span class="pun">.</span><span class="pln">list </span><span class="pun">></span> <span class="str">/dev/</span><span class="kwd">null</span>
现在添加了存储库并导入了签名密钥,我们可以继续安装 Docker。执行以下命令:
<span class="pln">sudo apt update sudo apt install docker</span><span class="pun">-</span><span class="pln">ce docker</span><span class="pun">-</span><span class="pln">ce</span><span class="pun">-</span><span class="pln">cli containerd</span><span class="pun">.</span><span class="pln">io</span>
安装 Docker 后,通过对 Docker 版本运行检查来确保已成功设置它:
<span class="pln">docker version</span>
第 3 步。轻松使用 Docker。
现在 Docker 已成功安装在 Debian 12 Bookworm 上,让我们通过一系列实际示例来探讨它的用法。
- 拉取码头工人镜像:
要使用 Docker,您需要从 Docker Hub 存储库中提取映像。使用以下命令搜索和拉取镜像:
<span class="pln">docker pull </span><span class="pun"><</span><span class="pln">image</span><span class="pun">-</span><span class="pln">name</span><span class="pun">></span>
- 正在运行的容器:
运行容器允许您利用 Docker 映像在隔离环境中执行应用程序。使用以下命令启动容器:
<span class="pln">docker run </span><span class="str"><options></span> <span class="pun"><</span><span class="pln">image</span><span class="pun">-</span><span class="pln">name</span><span class="pun">></span>
- 与容器交互:
管理正在运行的容器并与之交互对于有效使用 Docker 至关重要。以下是一些基本命令:
<span class="com">### Starting a container ###</span><span class="pln"> docker start </span><span class="pun"><</span><span class="pln">container</span><span class="pun">-</span><span class="pln">name</span><span class="pun">/</span><span class="pln">container</span><span class="pun">-</span><span class="pln">ID</span><span class="pun">></span> <span class="com">### Stopping a container ###</span><span class="pln"> docker stop </span><span class="pun"><</span><span class="pln">container</span><span class="pun">-</span><span class="pln">name</span><span class="pun">/</span><span class="pln">container</span><span class="pun">-</span><span class="pln">ID</span><span class="pun">></span> <span class="com">### Removing a container ###</span><span class="pln"> docker rm </span><span class="pun"><</span><span class="pln">container</span><span class="pun">-</span><span class="pln">name</span><span class="pun">/</span><span class="pln">container</span><span class="pun">-</span><span class="pln">ID</span><span class="pun">></span>
感谢您使用本教程在 Debian 11 书虫上安装最新版本的 Docker。有关其他帮助或有用信息,我们建议您查看 Docker 官方网站。