ubuntu 安装 docker

参考链接
https://docs.docker.com/engine/install/ubuntu/

环境

版本:Ubuntu 24.04.4 LTS

服务器:腾讯云轻量服务器 4核4G

操作系统要求

因为安装的 docker 版本对于 Ubuntu 的版本有要求,仅支持以下版本

  • Ubuntu Resolute 26.04 (LTS)
  • Ubuntu Noble 24.04 (LTS)
  • Ubuntu Jammy 22.04 (LTS)

Ubuntu 版本查询方式:

shell 复制代码
cat /etc/os-release

安装

1)删除旧的 docker 软件包

shell 复制代码
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

2)指定 apt 包管理的 docker 官方软件源

shell 复制代码
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
# 下载并保存 Docker 的 GPG 公钥
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# 添加 Docker 软件源配置文件
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

3)下载 docker 最新版本

shell 复制代码
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

4)验证 docker 是否安装成功

shell 复制代码
sudo systemctl status docker

更换镜像源

docker 默认下载使用的镜像源是国外的,国内访问速度慢,因此需要更换成国内的镜像源,提高镜像下载速度

1)编辑配置文件

shell 复制代码
sudo mkdir -p /etc/docker

2)添加镜像源

shell 复制代码
sudo vim /etc/docker/daemon.json
shell 复制代码
{
  "registry-mirrors": [
    "https://docker-0.unsee.tech",
    "https://hub.rat.dev",
    "https://hub.fast360.xyz",
    "https://docker.1panel.live"
  ]
}

第一条镜像源为华为云的,需要手动去到华为云申请(免费,链接:https://console.huaweicloud.com/swr/)

3)重启 docker 服务

shell 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

docker 启停命令

启动:

shell 复制代码
sudo systemctl start docker

停止:

shell 复制代码
sudo systemctl stop docker

重启:

shell 复制代码
sudo systemctl restart docker

查看 docker 状态:

shell 复制代码
sudo systemctl status docker
相关推荐
春涧草茶1 小时前
慢就是快12-12手动抛出异常
java·linux·前端
KING-WU5122 小时前
Linux 工具之Make 与 Makefile
java·linux·服务器
Lsetea2 小时前
OpenSSL报certificate is not yet valid:error 9与notBefore时间排查
linux·运维·https·ssl证书·openssl
魔法阵维护师2 小时前
Linux 命令行入门踩坑记录:从 VMware 装系统到文件管理
linux·运维·服务器
姜鱼问生3 小时前
docker exec 排查容器问题:从日志到进程
运维·网络·数据库·docker·容器
Apipi*3 小时前
30天速通Linux 第七章进程间通信
linux·运维·服务器
emo_2b3 小时前
Pycharm配置conda解释器时遇到的问题及解决方法
linux·pycharm·conda
人生百态,人生如梦4 小时前
Ubuntu在低版本下使用ccswitch+claudecode(CCSwitch+Docker+Claude)连调教程
linux·ubuntu·docker·claudecode·ccswitch
程序员老赵4 小时前
Docker 部署 OpenViking:轻松搭建 AI Agent 上下文数据库平台
docker·开源·agent
byte轻骑兵4 小时前
【BlueZ】hciconfig 工具:蓝牙适配器管理实操 + 源码实现基础
linux·bluez·电脑蓝牙·嵌入式蓝牙