Ubuntu 20.04.6 安装 docker

docker官方安装方法:docker 安装

其实,最好用的方法就是通过安装包直接安装docker desktop,技能同时安装最新版的docker,也拥有好用的docker界面,但遗憾的是,docker desktop仅支持 LTS version Ubuntu Jammy Jellyfish 22.04, 和 non-LTS version (Ubuntu Mantic Minotaur 23.10),不支持Ubuntu 20.04Ubuntu 24.04版本,因此只能选择单独安装docker

1. 如果你曾经安装过docker,必须卸载干净

1.1. 删除步骤1,官网给出的两条命令

sudo apt-get purge docker-ce docker-ce-cli containerd.io
 
sudo rm -rf /var/lib/docker

1.2. 删除步骤2

1.常归删除操作
sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd runc
 
2. 删除docker其他没有没有卸载
dpkg -l | grep docker
# 删除无用的相关的配置文件
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P 
 
3.卸载没有删除的docker相关插件(结合自己电脑的实际情况)
sudo apt-get autoremove docker-ce-*
 
4.删除docker的相关配置&目录
sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -rf /var/lib/docker
 
5.确认docker卸载完毕
docker --version

2. 开始安装

2.1. 按照官网要求,再次确认是否卸载完全

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

2.2. 安装 apt 依赖

sudo apt-get update

# 安装所需的依赖
sudo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  gnupg-agent \
  software-properties-common

2.3. 通过镜像网站添加 GPG 密钥并设置一个稳定的仓库

阿里源和清华源二选一即可

# 阿里源
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add - 
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs)

# 清华源
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 
add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" 

2.4. 再一次更新 apt

sudo apt-get update

2.5. 安装最新的 docker

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

2.6. 以非 Root 用户身份执行 Docker

# docker安装完成后,一般用户没有权限启动docker服务,只能通过sudo来通过root用户权限来启动docker。
# 为了方便,我们把普通用户加入到docker组中,docker组在安装docker的时候,就已经添加了,所以只需要执行两个操作即可:

sudo gpasswd -a $USER docker

newgrp docker

2.7. 重启docker

sudo systemctl restart docker

2.8. 配置镜像加速

另起一个命令窗口 Ctrl + Alt + T
cd /etc/docker/
 
查看是否有 daemon.json 文件,没有就创建
ls
 
创建 daemon.json 文件
touch daemon.json
 
编辑文件
$ sudo gedit /etc/docker/daemon.json
 
在弹出来的文本框中收入下面这段,保存
{
  "registry-mirrors": ["你自己的阿里云容器镜像加速器地址"]
}

2.9. 重启docker服务

sudo systemctl daemon-reload
sudo systemctl restart docker

2.10. 检验是否安装成功

sudo docker run hello-world

正确输出为:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值