ubuntu22.04安装docker

发布于:2025-08-08 ⋅ 阅读:(65) ⋅ 点赞:(0)

一、序言

记录一篇笔记方便日后使用,源ubuntu仓库的docker版本太低了,所以需要官网下载docker

# apt-cache show docker
Package: docker
Architecture: all
Version: 1.5-2

二、使用官网的方式安装

官网安装手册:https://docs.docker.com/engine/install/ubuntu/

配置docker仓库

# 卸载原有的包
apt-get remove docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc -y
apt-get update
apt-get install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update  

安装docker
下载最新版本

apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

下载指定版本
查看所有版本:

apt-cache madison docker-ce | awk '{ print $3 }'

下载指定版本:

sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

三、 使用阿里云的镜像源

最近我使用阿里云的仓库都是报错403,所以我决定在添加一个国内的镜像源

一样是先下载原有的docker,

添加阿里云提供的 Docker GPG 密钥:

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

使用阿里云的镜像仓库:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装docker

apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

四、使用清华源的镜像源

添加清华源提供的 Docker GPG 密钥:

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加 Docker 的软件源:

sudo add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

安装docker

apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

网站公告

今日签到

点亮在社区的每一天
去签到