ubuntu22.04 安装Docker

一、更新系统包索引

bash 复制代码
sudo apt update && sudo apt upgrade -y

二、安装必要依赖

安装 curlgnupg等工具,用于添加 Docker 官方 GPG 密钥和仓库:

bash 复制代码
sudo apt install -y ca-certificates curl gnupg

三、添加 Docker 官方 GPG 密钥

bash 复制代码
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  # 确保所有用户可读

四、添加 Docker 官方 APT 仓库

bash 复制代码
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

五、安装 Docker 引擎

bash 复制代码
sudo apt update  # 刷新仓库缓存
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

六、配置镜像加速器

bash 复制代码
vi /etc/docker/daemon.json
bash 复制代码
{
  "registry-mirrors": [
    "https://docker.1ms.run"
  ]
}

七、重启docker

bash 复制代码
sudo systemctl restart docker

八、验证 Docker 安装

复制代码
sudo docker run hello-world
bash 复制代码
Hello from Docker!
This message shows that your installation appears to be working correctly.
...

可选:免 sudo 使用 Docker(推荐)​

默认情况下,只有 root用户或 docker组的用户可以执行 Docker 命令。为了避免每次使用 sudo,可以将当前用户添加到 docker组:

1.创建 docker组(若不存在):

bash 复制代码
sudo groupadd docker

2.将当前用户加入 docker组:

bash 复制代码
sudo usermod -aG docker $USER

3.生效组权限(需重新登录或执行以下命令):

bash 复制代码
newgrp docker

4.验证免 sudo权限:

bash 复制代码
docker run hello-world  # 无需 sudo
相关推荐
天才奇男子13 小时前
HAProxy高级功能全解析
linux·运维·服务器·微服务·云原生
小李独爱秋14 小时前
“bootmgr is compressed”错误:根源、笔记本与台式机差异化解决方案深度指南
运维·stm32·单片机·嵌入式硬件·文件系统·电脑故障
学嵌入式的小杨同学14 小时前
【Linux 封神之路】信号编程全解析:从信号基础到 MP3 播放器实战(含核心 API 与避坑指南)
java·linux·c语言·开发语言·vscode·vim·ux
酥暮沐14 小时前
iscsi部署网络存储
linux·网络·存储·iscsi
❀͜͡傀儡师15 小时前
centos 7部署dns服务器
linux·服务器·centos·dns
Dying.Light15 小时前
Linux部署问题
linux·运维·服务器
S190115 小时前
Linux的常用指令
linux·运维·服务器
萤丰信息15 小时前
AI 筑基・生态共荣:智慧园区的价值重构与未来新途
大数据·运维·人工智能·科技·智慧城市·智慧园区
小义_15 小时前
【RH134知识点问答题】第7章 管理基本存储
linux·运维·服务器
运维小欣15 小时前
Agentic AI 与 Agentic Ops 驱动,智能运维迈向新高度
运维·人工智能