Ubuntu 24.04 安装 Docker

1. 清理旧版本

bash 复制代码
sudo apt remove docker docker-engine docker.io containerd runc

2. 更新系统并安装依赖工具

bash 复制代码
sudo apt update

sudo apt install -y \
    ca-certificates \
    curl \
    gnupg \
    lsb-release \
    software-properties-common

3. 添加 Docker 官方 GPG 密钥

使用阿里云镜像

bash 复制代码
# 创建密钥存储目录
sudo install -m 0755 -d /etc/apt/keyrings

# 下载并添加 Docker 的官方 GPG 密钥(使用阿里云镜像)
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# 设置密钥文件权限
sudo chmod a+r /etc/apt/keyrings/docker.gpg

4. 添加 Docker 软件源

使用阿里云镜像

bash 复制代码
# 添加 Docker 软件源(使用阿里云镜像)
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5. 安装 Docker Engine

bash 复制代码
# 更新软件包索引
sudo apt update

# 安装 Docker
sudo apt install -y docker-ce docker-ce-cli containerd.io

# 检查安装的版本
docker --version

6. 配置国内Docker镜像加速器

注意,国内的加速器有些已经失效,有些限制了使用范围,优先使用 ping 排除失效的。

bash 复制代码
# 创建 Docker 配置目录(如果不存在)
sudo mkdir -p /etc/docker

# daemon.json 配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.1ms.run",
    "https://docker.xuanyuan.me",
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com",
    "https://<your_code>.mirror.aliyuncs.com"
  ]
}
EOF

# 重启 Docker 使加速配置生效
sudo systemctl daemon-reload
sudo systemctl restart docker

# 验证加速器是否生效
docker info | grep -i mirror

7. 验证安装

bash 复制代码
# 检查 Docker 服务状态
sudo systemctl status docker

# 运行测试容器
sudo docker run hello-world

8、说明

(1)镜像加速器地址无效

docker run hello-world

Unable to find image 'hello-world:latest' locally

docker: Error response from daemon: failed to resolve reference "docker.io/library/hello-world:latest": failed to do request: Head "https://hub-mirror.c.163.com/v2/library/hello-world/manifests/latest?ns=docker.io": dial tcp: lookup hub-mirror.c.163.com on 127.0.0.53:53: no such host

(2)镜像加速器限制了使用范围

docker run hello-world

Unable to find image 'hello-world:latest' locally

docker: Error response from daemon: unknown: failed to resolve reference "docker.io/library/hello-world:latest": unexpected status from HEAD request to https://xxxxxxxx.mirror.aliyuncs.com/v2/library/hello-world/manifests/latest?ns=docker.io: 403 Forbidden

限制在阿里云内部使用

相关推荐
lifewange11 分钟前
Linux ps 进程查看命令详解
linux·运维·服务器
功德+n19 分钟前
Linux下安装与配置Docker完整详细步骤
linux·运维·服务器·开发语言·docker·centos
问简1 小时前
ubuntu24 主题经验
ubuntu
小敬爱吃饭1 小时前
Ragflow Docker部署及问题解决方案(界面为Welcome to nginx,ragflow上传文件失败,Docker中的ragflow-cpu-1一直重启)
人工智能·python·nginx·docker·语言模型·容器·数据挖掘
左手厨刀右手茼蒿1 小时前
Linux 内核中的块设备驱动:从原理到实践
linux·嵌入式·系统内核
杨云龙UP1 小时前
从0到1快速学会Linux操作系统(基础),这一篇就够了!
linux·运维·服务器·学习·ubuntu·centos·ssh
HXQ_晴天1 小时前
Ubuntu 设置中文输入法
linux·运维·ubuntu
Dovis(誓平步青云)1 小时前
《Linux 信号入门:搞懂 “进程通信的紧急电话” 到底怎么用(初篇)》
linux·运维·服务器
左手厨刀右手茼蒿1 小时前
Linux 内核中的模块机制:从加载到卸载
linux·嵌入式·系统内核