当前位置: 首页 > news >正文

Ubuntu 24.04 LTS系统安装Docker踩的坑

一开始我跟着Docker给出的官网文档 Ubuntu | Docker Docs 流程走,倒腾了两个多小时,遇到了各种坑,最后放弃了。在我们使用脚本安装Docker命令前,我们先把已经安装的Docker全部卸载掉。

卸载Docker

1.删除docker及安装时自动安装的所有包

sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd runc

2.查看docker是否卸载干净

sudo dpkg -l | grep dockersudo dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P  # 删除无用的相关的配置文件

3.删除没有删除的相关插件

sudo apt-get autoremove docker-ce-*

4.删除docker的相关配置&目录

rm -rf /etc/systemd/system/docker.service.d
5.确定docker卸载完毕
docker --version

然后根据 docker官方一键脚本 这个教程使用官方脚本自动安装Docker,前三步成功了,第四步出问题了。

安装Docker

1. 下载官方安装脚本

curl -fsSL https://test.docker.com -o test-docker.sh

2. 执行脚本

sudo sh test-docker.sh

3. 查看Docker版本信息,若能输出版本信息则证明安装成功

chen@QiLin:~$ sudo docker version[sudo] password for chen: 
Client: Docker Engine - CommunityVersion:           27.5.0-rc.2API version:       1.47Go version:        go1.22.10Git commit:        80f7848Built:             Tue Jan  7 15:41:26 2025OS/Arch:           linux/amd64Context:           defaultServer: Docker Engine - CommunityEngine:Version:          27.5.0-rc.2API version:      1.47 (minimum version 1.24)Go version:       go1.22.10Git commit:       43fc912Built:            Tue Jan  7 15:41:26 2025OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.7.24GitCommit:        88bf19b2105c8b17560993bee28a01ddc2f97182runc:Version:          1.2.2GitCommit:        v1.2.2-0-g7cb3632docker-init:Version:          0.19.0GitCommit:        de40ad0

4. 尝试运行hello-world镜像来验证Docker是否正确安装

chen@QiLin:~$ sudo docker run hello-worldUnable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": read tcp 10.16.6.16:38474->54.227.20.253:443: read: connection reset by peer.
See 'docker run --help'.

网上教程说在使用Docker拉取镜像时,有时会遇到 Error response from daemon 错误是由于 Docker 无法在规定时间内成功连接到 Docker Hub 或由于网络不稳定而超时引起的。解决这一问题的有效方法是配置 Docker 镜像加速器,提高拉取镜像的速度,避免因网络超时而失败。

解决方法:配置 Docker 镜像加速器

为了避免 Docker 镜像拉取失败,我们可以配置国内或其他可用的镜像源加速器,减少网络连接的超时问题。打开 Docker 的配置文件 daemon.json。该文件通常位于:/etc/docker/daemon.json,然后添加镜像加速器。

sudo vi /etc/docker/daemon.json
{"registry-mirrors": ["https://docker.hpcloud.cloud","https://docker.m.daocloud.io","https://docker.unsee.tech","https://docker.1panel.live","http://mirrors.ustc.edu.cn","https://docker.chenby.cn","http://mirror.azure.cn","https://dockerpull.org","https://dockerhub.icu","https://hub.rat.dev"]
}

这些镜像源能够有效加速 Docker 镜像的下载,尤其是在国内的网络环境下,可以显著提高镜像拉取速度,并减少因网络不稳定导致的超时错误。

最终我的 daemon.json文件包含如下内容,小伙伴们可以尽情copy。

{"insecure-registries": ["registry.local", "127.0.0.1:5001", "10.10.13.42:5000"],"registry-mirrors": ["https://docker.hpcloud.cloud","https://docker.m.daocloud.io","https://docker.unsee.tech","https://docker.1panel.live","http://mirrors.ustc.edu.cn","https://docker.chenby.cn","http://mirror.azure.cn","https://dockerpull.org","https://dockerhub.icu","https://hub.rat.dev"],"bip": "172.18.18.1/24","data-root": "/var/lib/docker","storage-driver": "overlay2","live-restore": true,"log-opts": {"max-size": "500m"}
}

注意:在编辑 daemon.json 文件时,确保 JSON 格式正确。特别注意,最后一个镜像加速器地址后不要加逗号,否则会导致 Docker 启动失败。如果使用某些镜像加速器时依然遇到问题,可能是这些加速器暂时不可用。建议更换其他加速器,或者使用官方的 Docker 镜像加速服务。

配置完成后,保存文件并重启 Docker 服务,以使更改生效。

sudo systemctl daemon-reload
sudo systemctl restart docker

然后重新运行:sudo docker run hello-world

sudo docker run hello-worldUnable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:5b3cc85e16e3058003c13b7821318369dad01dac3dbb877aac3c28182255c724
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

成功!!!!!

http://www.lryc.cn/news/519621.html

相关文章:

  • 工作生活的感悟
  • NCCL学习笔记-函数解析
  • windows系统如何将基座大模型私有化部署
  • 牛客网刷题 ——C语言初阶(6指针)——BC106 上三角矩阵判定
  • CentOS 7 下 MySQL 5.7 的详细安装与配置
  • 【深度学习】数据预处理
  • day01-HTML-CSS——基础标签样式表格标签表单标签
  • 无需昂贵GPU:本地部署开源AI项目LocalAI在消费级硬件上运行大模型
  • 搭建prometheus+grafana监控系统抓取Linux主机系统资源数据
  • uni-app无限级树形组件简单实现
  • 基于华为ENSP的OSPF状态机、工作过程、配置保姆级别详解(2)
  • 请求方式(基于注解实现)
  • day38 tcp 并发 ,linux下的IO模型----IO多路复用
  • 更新Office后,LabVIEW 可执行程序生成失败
  • 重塑视频创作的格局!ComfyUI-Mochi本地部署教程
  • 如何理解机器学习中的非线性模型 ?
  • Web 品质样式表
  • 计算机网络 笔记 数据链路层3(局域网,广域网,网桥,交换机)
  • centos7.6 安装nginx 1.21.3与配置ssl
  • redis 内存管理和持久化机制
  • python-42-使用selenium-wire爬取微信公众号下的所有文章列表
  • 机器人碳钢去毛刺,用大扭去毛刺主轴可轻松去除
  • day05_Spark SQL
  • Java线程的异常处理:确保线程安全运行
  • nvim 打造成可用的IDE(2)
  • 如何当前正在运行的 Elasticsearch 集群信息
  • PHP Filesystem:深入解析与实战应用
  • pdf提取文本,表格以及转图片:spire.pdf
  • jQuery UI 主题
  • C# GDI+的DrawString无法绘制Tab键的现象