ubuntu20.04傻瓜安装&测试docker实录

ubuntu20.04傻瓜安装&测试docker实录


所谓傻瓜安装,即按照本实录,除手动选择版本外,完全照搬代码即可实现docker社区版安装。
本实录为Ubuntu20.04安装docker,虚拟机的安装理论上可照搬,但Ubuntu16之前的版本过老,无法安装新版docker。Windows10自带的wsl2所安装的ubuntu由于不兼容问题,本实录是无法作为参考的,甚至于笔者也未找到wsl2安装docker合适的方式。 若有读者希望使用wsl2安装docker,笔者建议立即放弃,转而使用虚拟机或双系统ubuntu! 也欢迎放弃win10早日步入linux神殿/doge

docker安装

ubuntu20.04自带docker旧版,笔者没使用过,但强迫症让我删除了所有旧版并立即安装了最新版。删除代码如下:

$sudo apt-get remove docker docker-engine docker-ce docker.io

不管安装啥,首先给系统更新!安装docker必要的依赖软件,来添加一个新的 HTTPS 软件源:

$sudo apt update
$sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

使用下面的 curl 导入源仓库的 GPG key:

$curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

将 Docker APT 软件源添加到系统:

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

现在,Docker 软件源被启用了,可以安装软件源中可用的 Docker 版本。
再给系统更新一下,获取新安装列表。可以使用以下方法自动安装最新的docker社区,也可以跳过此步手动选择想安装的版本。

$sudo apt update
$sudo apt install docker-ce docker-ce-cli containerd.io

手动安装如下:
先列出所有可以安装的docker版本

$sudo apt update
$sudo apt list -a docker-ce

上述代码展示笔者电脑当前可以安装的版本:
在这里插入图片描述
使用以下命令指定版本安装,将两个=<VERSION>改为目标的版本号,例如我安装的最新版:=5:20.10.5~3-0~ubuntu-focal

$sudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io

hello-world测试

安装成功后可以用以下命令测试:

$sudo docker run hello-world

hello-world是一个轻量级的镜像,专门用来提供给docker新手测试docker的安装是否成功。在上述指令运行后会自动开始安装hello-world镜像,若在安装过程中没有出现ERRO基本上就是安装成功了。再次输入上述指令后出现以下就代表安装成功了!恭喜加入docker的大家庭!

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/]:(https://docs.docker.com/get-started/)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

winnower-sliff

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值