我分别用18、20和最新的22测试过,都正常安装成功。

1、卸载旧版本

sudo apt-get remove docker docker-engine docker.io containerd runc

2、安装必要的一些系统工具

sudo apt-get update

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common gnupg-agent

3、安装GPG证书

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

4、写入软件源信息

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

5、更新并安装Docker-CE

sudo apt-get -y update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io

sudo apt install -y python3-pip

sudo pip3 install docker-compose

Ubuntu 安装 Docker

你需要这些Ubuntu版本中的一个64位版本

  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)
# 1. 卸载docker
sudo apt-get remove docker docker-engine docker.io containerd runc

# 2. 更新包索引
sudo apt-get update

# 3. 安装依赖
sudo apt-get -y install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# 4. 添加 docker 官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 5. 添加安装 docker 软件源
# 这个是官方的
# sudo add-apt-repository \
#    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
#    $(lsb_release -cs) \
#    stable"
# 使用阿里云的源比较快
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# 6. 更新软件包索引
sudo apt-get -y update

# 7. 安装docker相关的    docker-ce 社区版    ee企业版
sudo apt-get -y install docker-ce docker-ce-cli containerd.io

# 8. 跑一下
sudo docker run hello-world

# 如果报错了就启动一下 docker 服务再去跑
作者:Jeebiz  创建时间:2023-03-28 22:51
最后编辑:Jeebiz  更新时间:2024-08-02 14:21