0


Docker: ubuntu系统下Docker的安装

安装依赖

操作系统版本

  • Ubuntu Kinetic 22.10
  • Ubuntu Jammy 24.04 (LTS)
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

CPU架构支持

  • ARM
  • x86_64

查看我们的系统版本信息

  1. uname -a

在这里插入图片描述
通过该命令查得cpu架构是x86_64的;

  1. cat /etc/*release*

在这里插入图片描述
查看得到版本信息是20.04的;

如果版本号跟不上的话,是不支持最新的Docker的;

卸载旧版本或历史版本的Docker

如果系统镜像是新搭建的,是没有包含docker的,可以跳过这一步;
我们也可以通过 输入

  1. docker

来验证你是否有安装:
有安装的话:
在这里插入图片描述

卸载旧版本:

  1. sudo apt-get remove docker docker-engine docker.io containerd runc

卸载历史版本:

  1. #卸载软件
  2. sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras -y
  3. #删除目录
  4. sudo rm -rf /var/lib/docker
  5. sudo rm -rf /var/lib/containerd

配置docker下载源

  1. #curl命令安装
  2. sudo apt install curl -y
  3. #安装必要的包 添加Docker的官方GPG密钥
  4. sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
  5. curl -fsSL https://mirrors.aliyun.codocker-ce/linux/ubuntu/gpg | sudo apt-key add -

GPG密钥是一种用于数据加密、数字签名和安全通信的工具。在安装软件包时,GPG密钥可以确保用户下载的软件包是来自官方或可信任的源,且没有在传输过程中被篡改或损坏。
用户需要从Docker的官方网站或其他可信任的源下载GPG密钥,下载完成后,用户需要将GPG密钥导入到系统的GPG密钥环中。

常见错误

  1. curl:(35) OpenSSL SSL_connect: Connection reset by peer in connection to download.docker.com:443 gpg: no valid OpenPGP data found.

这个错误通常意味着在尝试通过 HTTPS 连接到

  1. download.docker.com

时,连接被远程服务器重置。这可能是由于网络问题、DNS 解析问题或服务器端的配置错误导致的。

我们可以先ping 一下该网站是否能够连接上:

  1. ping download.docker.com

可以的话,有时服务器可能暂时不可用或正在维护。等待一段时间后重试可能会解决问题。多输入几遍到不报错为止。

安装docker

由于下载官方安装包的时候下载过慢,所以这里通过阿里云的下载源来进行下载。

  1. #添加阿里云镜像的Docker APT源
  2. sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  3. #更新APT包索引
  4. sudo apt update
  5. #安装Docker CE(Community Edition)
  6. sudo apt install docker-ce docker-ce-cli containerd.io -y

常见错误(没有公钥)

apt update时

  1. W: GPG error: https://download.docker.com/linux/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
  2. E: The repository 'https://download.docker.com/linux/ubuntu focal InRelease' is notsigned.

这是由于没有公钥,无法验证下列签名,
解决方法:可以通过以下命令来添加缺失的公钥

  1. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8

将会从Ubuntu的公钥服务器上获取缺失的公钥并将其添加到你的系统中。然后,重新运行apt update命令来更新软件包列表。

常见错误(没有 Release 文件)

第一种方法

apt update时

  1. The repository 'https://download.docker.com/linux/ubuntu focal Release' does not have a Release file.

这通常意味着您尝试访问的 Docker 仓库分支或版本不存在或已更改。

解决方法:更新Ca-certificates
Ca-certificates官网

找到对应版本,进入详情
在这里插入图片描述
滑到下面找到Download,复制链接
在这里插入图片描述

  1. wget http://ports.ubuntu.com/pool/main/c/ca-certificates/ca-certificates_20240203~20.04.1_all.deb
  2. sudo dpkg -i ca-certificates_20240203~20.04.1_all.deb

输入命令进行下载解压

  1. sudo apt update

再次更新

第二种方法

更新source源:网站:国内source源
在这里插入图片描述
找到对应版本选择下载,之后输入命令:对你的sources.list源进行拷贝更新

  1. sudo cp sources.list /etc/apt

再次尝试

  1. sudo apt update

自动启动配置

  1. #配置加载
  2. sudo systemctl daemon-reload
  3. #启动服务
  4. sudo systemctl start docker
  5. #开启启动
  6. sudo systemctl enable docker
  7. # 查看服务状态
  8. sudo systemctl status docker

在这里插入图片描述

这是是绿色的表明服务是正常运行的;

查看docker版本

  1. docker version

在这里插入图片描述

查看更详细信息

  1. docker info

对docker镜像源的更改

默认情况下,Docker使用的是官方的镜像源,如Docker Hub。然而,由于网络条件地理位置官方镜像源本身的限制,下载速度可能会较慢,导致在构建容器时等待时间过长。
为了提高下载速度,许多用户会选择将镜像源更改为国内的镜像源,如阿里云、DaoCloud等提供的加速器。这些加速器通常位于国内,能够更快地响应用户的下载请求,从而显著提高下载速度。

  1. vim /etc/docker/daemon.json
  1. {"registry-mirrors":["https://mirror.ccs.tencentyun.com","https://docker.registry.cyou","https://docker-cf.registry.cyou","https://dockercf.jsdelivr.fyi","https://docker.jsdelivr.fyi","https://dockertest.jsdelivr.fyi","https://mirror.aliyuncs.com","https://dockerproxy.com","https://mirror.baidubce.com","https://docker.m.daocloud.io","https://docker.nju.edu.cn","https://docker.mirrors.sjtug.sjtu.edu.cn","https://docker.mirrors.ustc.edu.cn","https://mirror.iscas.ac.cn","https://docker.rainbond.cc"],"data-root":"/data/var/lib/docker"}

重新启动

  1. sudo systemctl restart docker

Docker目录的更改

Docker 默认的安装目录为/var/lib/docker,这里面会存放很多很多镜像,所以我们在安装的时候需要考虑这个目录的空间,为了增大空间的上限,我们给它换一个大的磁盘。

  1. #假定我们磁盘的大的目录为 /data
  2. mkdir -p /data/var/lib/docker
  3. # 编辑配置文件
  4. vi /etc/docker/daemon.json
  5. # 输入下面的 json
  6. {"data-root":"/data/var/lib/docker"}
  7. # 加载配置
  8. sudo systemctl daemon-reload
  9. # 重启 docker
  10. sudo systemctl restart docker
  11. #查看 docker 状态
  12. sudo systemctl status docker

通过命令

  1. docker info

查得
在这里插入图片描述

发现该目录下已经加载了配置了。
在这里插入图片描述

尝试运行

  1. docker run hello-world

在这里插入图片描述
只要出现了红框内容,那么就是安装成功的。


参考来源:E:The repository ‘https://mirrors.aliyun.com/docker-ce/linux/ubuntu una Release‘ does not have a Rel
解决E: 仓库 “https://download.docker.com/linux/ubuntu focal Release” 不再含有 Release 文件

标签: docker ubuntu 容器

本文转载自: https://blog.csdn.net/m0_74068921/article/details/143446933
版权归原作者 诡异森林。 所有, 如有侵权,请联系我们删除。

“Docker: ubuntu系统下Docker的安装”的评论:

还没有评论