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/)