在太阳下
不管你喜不喜欢,高不高兴,爱与不爱;太阳照旧照耀着你!温暖着你!

Debian 11 手动安装 Docker 和 Docker Compose 最新版

Debian 11 手动安装 Docker 和 Docker Compose 最新版
TIME 2023-06-18 20:24

一键安装Docker 和 Docker Compose 最新版命令

apt-get update ; apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y ; curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ; echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null ; apt-get update -y ; apt-get install docker-ce docker-ce-cli containerd.io -y ; docker run hello-world ; cd /usr/local/bin/ ; wget https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 ; mv docker-compose-linux-x86_64 docker-compose ; ls -lh ; chmod +x /usr/local/bin/docker-compose ; docker --version ; docker-compose --version

返回结果

Docker version 24.0.2, build cb74dfc
Docker Compose version v2.18.1

详细步骤如下….

安装 Docker
1.先更新你的现有列表软件包:

apt-get update

2.安装一些必需的软件包,允许 apt 在 HTTPS 上使用存储库(repository):

apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

3.添加 Docker 的官方 GPG 密钥:

curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4.使用以下命令设置稳定的存储库:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

5.更新 apt 包索引,并安装最新版本的 Docker CE:

apt-get update -y ; apt-get install docker-ce docker-ce-cli containerd.io -y

6.验证 Docker 是否正确安装,使用以下命令,如果正确安装,它会输出一个欢迎消息:

docker run hello-world

返回结果

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:c2e23624975516c7e27b1b25be3682a8c6c4c0cea011b791ce98aa423b5040a0
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

你刚刚运行了 Docker 的 “hello-world” 图像。这是 Docker 的一个入门程序,用于确认 Docker 是否已经正确安装并可以在你的机器上运行。从输出来看,你的 Docker 安装看起来是成功的。这里是每个步骤的意义:

1. Docker 客户端(你在命令行中运行的程序)联系了 Docker 守护进程(在后台运行的服务)。
2. Docker 守护进程从 Docker Hub(一个存储 Docker 镜像的公共库)下载了 “hello-world” 镜像。
3. Docker 守护进程从该镜像创建了一个新的容器,并运行了一个可执行文件,这个可执行文件产生了你当前正在阅读的输出。
4. Docker 守护进程将这个输出流发送给 Docker 客户端,客户端再将它发送给你的终端显示。

接下来,你可以尝试更多的操作,例如运行一个 Ubuntu 容器:`docker run -it ubuntu bash`。此外,你也可以在 Docker Hub 创建一个免费的 Docker ID,以分享镜像,自动化工作流等。对于更多的示例和想法,你可以访问 Docker 的开始使用指南:https://docs.docker.com/get-started/。

查看已安装的 Docker 版本

docker --version

返回的结果

Docker version 24.0.2, build cb74dfc

正在运行的 Docker 的版本是 24.0.2,并且这个版本的构建(build)标识是 cb74dfc。在这里,”构建”是指 Docker 这个软件在编译时的特定版本,它可以帮助开发者跟踪问题或者理解特定版本的 Docker 的行为。

安装 Docker Compose
1.从 GitHub 的 Docker Compose 存储库下载 Docker Compose 的当前稳定版本:

curl -L "https://github.com/docker/compose/releases/download/2.18.1/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose

请注意在上述命令中,你可能需要将版本号(在本例中为 “2.18.1”)替换为你要下载的最新版本号
查看最新版的查询地址:https://github.com/docker/compose/releases/
目前的最新版是:v2.18.1

这是一个使用 curl 命令从 GitHub 下载 Docker Compose 的操作。

  • curl -L 命令告诉 curl 跟踪重定向,因为 GitHub 通常会将文件存储在不同的位置,并使用重定向来引导到正确的下载位置。
  • "https://github.com/docker/compose/releases/download/2.18.1/docker-compose-Linux-x86_64" 是适配与当前Debian11x64系统的 Docker Compose 版本。
  • -o /usr/local/bin/docker-compose 参数指定了下载文件的保存位置,这里是 /usr/local/bin/docker-compose

返回结果

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100     9  100     9    0     0     35      0 --:--:-- --:--:-- --:--:--    35
这个输出是 curl 命令的进度条。根据你的输出,它显示的是你下载的文件大小只有9字节,这是不正常的,因为 Docker Compose 的二进制文件应该有50兆字节。

重新换一种方式下载吧

cd /usr/local/bin/ ; wget https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 ; mv docker-compose-linux-x86_64 docker-compose ; ls -lh

检查 docker-compose 文件体积是不是 53M

2.将下载的二进制文件的可执行权限应用到二进制文件

chmod +x /usr/local/bin/docker-compose

3.测试安装是否成功:

docker-compose --version

返回结果

Docker Compose version v2.18.1

这表示你已经成功安装了 Docker Compose,并且当前的版本是v2.18.1

查询 Docker 和 Docker Compose 版本

docker --version ; docker-compose --version

返回结果

Docker version 24.0.2, build cb74dfc
Docker Compose version v2.18.1

点击数:15

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
Verified by MonsterInsights