【Ubuntu】安装Docker

一、查看系统基本情况

1.1 查看系统版本


指令一

bash 复制代码
lsb_release -a
  • No LSB modules are available.
  • Distributor ID: Ubuntu
  • Description: Ubuntu 20.04.6 LTS
  • Release: 20.04
  • Codename: focal

指令二

bash 复制代码
cat /etc/lsb-release 
  • DISTRIB_ID=Ubuntu
  • DISTRIB_RELEASE=20.04
  • DISTRIB_CODENAME=focal
  • DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

1.2 查看系统架构

bash 复制代码
sudo dpkg  --print-architecture
  • arm64

1.3 查看容器架构

bash 复制代码
uname -m
  • aarch64

二、使用apt仓储进行安装

在新主机上首次安装Docker引擎之前,您需要设置Docker存储库。之后,您可以从存储库中安装和更新Docker。

2.1 设置Docker的apt仓库。

bash 复制代码
# 添加Docker的官方GPG密钥:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# 将仓库添加到Apt源:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

提示

如果您使用Ubuntu衍生发行版,如Linux Mint,则可能需要使用Ubuntu_CODENAME而不是VERSION_CODENAME。

2.2 安装Docker软件包。

2.2.1 安装最新版

要安装最新版本,请运行:

bash 复制代码
sudo apt-get install docker-ce docker-ce-cli containerd.io 

2.2.2 安装指定版本

要安装特定版本的Docker引擎,请首先在存储库中列出可用版本:

bash 复制代码
# 列出可用版本:
apt-cache madison docker-ce | awk '{ print $3 }'

5:24.0.0-1~ubuntu.22.04~jammy
5:23.0.6-1~ubuntu.22.04~jammy
...

选择所需的版本并安装:

bash 复制代码
VERSION_STRING=5:24.0.0-1~ubuntu.22.04~jammy
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

2.3 通过运行 hello-world 镜像来验证Docker引擎安装是否成功。

bash 复制代码
sudo docker run hello-world

此命令下载测试映像并在容器中运行。当容器运行时,它会打印一条确认消息Hello from Docker!并退出。

bash 复制代码
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
70f5ac315c5a: Pull complete 
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
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.
    (arm64v8)
 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/

提示

尝试在没有root用户的情况下运行时收到错误?

docker用户组存在,但不包含任何用户,这就是为什么需要使用sudo来运行docker命令。继续Linux postinstall,允许非特权用户运行Docker命令和其他可选的配置步骤。

更新Docker引擎

要升级Docker引擎,请按照安装说明的步骤2,选择要安装的新版本。

如果出现下面情况,安装更新源与系统不匹配,设置合适的源或手动安装`

bash 复制代码
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
没有可用的软件包 docker-ce,但是它被其它的软件包引用了。
这可能意味着这个缺失的软件包可能已被废弃,
或者只能在其他发布源中找到

E: 软件包 docker-ce 没有可安装候选
E: 无法定位软件包 docker-ce-cli
E: 无法定位软件包 containerd.io
E: 无法按照 glob 'containerd.io' 找到任何软件包
E: 无法按照正则表达式 containerd.io 找到任何软件包

三、下载相关安装包手动安装

如果你不能使用Dockerapt仓库来安装Docker引擎,你可以下载发布的deb文件并手动安装。每次升级Docker引擎时,都需要下载一个新文件。

  1. 资源地址 ++https://download.docker.com/linux/ubuntu/dists/++
  2. 在列表中选择你的Ubuntu 版本
  • 我的Ubuntu版本 - Codename: focal
  1. 选择子目录 pool/stable/ 并且选择架构 (amd64, armhf, ppc64el, arm64, 或者 s390x).
    如:我的系统是那么文件路径为:
  • 我的硬件架构 - arm64

针对我的系统Docker资源下载路径:

https://download.docker.com/linux/ubuntu/dists/`focal`/pool/stable/`arm64`/

  1. 下载Docker Engine、CLI、containerd和Docker Compose包的以下deb文件:
    ++下载地址++
  • containerd.io_1.3.7-1_arm64.deb
  • docker-ce-cli_19.03.13~3-0~ubuntu-focal_arm64.deb
  • docker-ce_19.03.13~3-0~ubuntu-focal_arm64.deb
  1. 安装.deb包。将以下示例中的路径更新为下载Docker软件包的位置。

方式一、sudo dpkg -i

bash 复制代码
sudo dpkg -i ./containerd.io_<version>_<arch>.deb \
  ./docker-ce_<version>_<arch>.deb \
  ./docker-ce-cli_<version>_<arch>.deb \
  ./docker-buildx-plugin_<version>_<arch>.deb \
  ./docker-compose-plugin_<version>_<arch>.deb

方式二、sudo apt-get install

bash 复制代码
sudo apt-get install /home/signway/download/containerd.io_1.3.7-1_arm64.deb
bash 复制代码
sudo apt-get install /home/signway/download/docker-ce-cli_19.03.13~3-0~ubuntu-focal_arm64.deb
bash 复制代码
sudo apt-get install /home/signway/download/docker-ce_19.03.13~3-0~ubuntu-focal_arm64.deb

注意 Docker守护进程会自动启动。

验证Docker是否安装完成

运行hello-world镜像来验证Docker引擎是否安装成功!

bash 复制代码
 sudo service docker start
bash 复制代码
sudo docker run hello-world
相关推荐
不烦下雨c36 分钟前
[网络]抓包工具介绍 tcpdump
linux·tcpdump
南瓜小米粥、1 小时前
通过fdisk初始化Linux数据盘
linux·运维·服务器
秋风起,再归来~1 小时前
【Linux庖丁解牛】—Linux基本指令(中)!
linux·指令
Eternal-Student1 小时前
预处理、编译、汇编、链接
linux·汇编·windows
sp_wxf2 小时前
Stream流
linux·服务器·windows
LYK_HAHA2 小时前
centos常用知识和命令
linux·运维·centos
老齐谈电商3 小时前
开源电商erp系统启航电商ERP系统centos Docker部署
docker·开源·centos
可涵不会debug3 小时前
【Linux】信号知识三把斧——信号的产生、保存和处理
linux·运维·信号
jyan_敬言3 小时前
【Linux】Linux命令与操作详解(一)文件管理(文件命令)、用户与用户组管理(创建、删除用户/组)
linux·运维·服务器·c语言·开发语言·汇编·c++
unix2linux4 小时前
Parade Series - SHA256
linux·python·mysql·shell