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 docker

sudo 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 - Community
 Version:           27.5.0-rc.2
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        80f7848
 Built:             Tue Jan  7 15:41:26 2025
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.5.0-rc.2
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       43fc912
  Built:            Tue Jan  7 15:41:26 2025
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.24
  GitCommit:        88bf19b2105c8b17560993bee28a01ddc2f97182
 runc:
  Version:          1.2.2
  GitCommit:        v1.2.2-0-g7cb3632
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

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

chen@QiLin:~$ sudo docker run hello-world

Unable 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-world

Unable 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: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/

成功!!!!!

### AnythingLLM 在 Ubuntu 上的安装、配置与使用 #### 安装 Docker 和 Buildx 插件 为了运行和部署 AnythingLLM 项目,Docker 是必需的基础环境之一。对于 Docker 的扩展功能支持,则可以通过安装 `buildx` 来实现更灵活的镜像构建。 创建目录并放置 `docker-buildx` 文件至指定位置,赋予执行权限以便后续操作能够顺利进行[^1]: ```bash mkdir -p ~/.docker/cli-plugins mv buildx-${BUILDX_VERSION}.linux-amd64 ~/.docker/cli-plugins/docker-buildx chmod +x ~/.docker/cli-plugins/docker-buildx ``` #### 获取 AnythingLLM 源码库 通过 Git 工具克隆官方维护的 AnythingLLM 仓库到本地机器上,这一步骤会下载整个项目的最新版本以及历史记录等信息[^2]。 ```bash git clone https://github.com/Mintplex-Labs/anything-llm.git cd anything-llm ``` #### 设置开发环境 进入刚拉取下来的项目文件夹之后,按照文档指示完成必要的软件包和其他工具链的准备工作。通常情况下,这涉及到 Python 解释器及其 pip 包管理系统的设置,以及其他可能需要用到的服务端组件(比如 Redis 或者 RabbitMQ)。具体命令取决于实际需求和项目说明中的指导。 #### 配置与启动服务 依据个人喜好或是生产环境中既定的标准来调整应用参数设定;接着利用 Makefile 提供的目标或者是直接调用脚本来激活容器化应用程序实例。确保所有外部连接都已正确建立,并验证 API 接口能否正常响应请求。 #### 日常运维与监控 定期检查日志输出以发现潜在错误或性能瓶颈所在之处。借助 Prometheus/Grafana 这样的开源平台来进行实时数据采集分析工作,从而保障线上业务稳定可靠地运转下去。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值