要安装Docker Engine,您需要以下Ubuntu版本之一的64位版本:
Ubuntu Focal 20.04(LTS)
Ubuntu Eoan 19.10
Ubuntu Bionic 18.04(LTS)
Ubuntu Xenial 16.04(LTS)
Docker Engine在x86_64(或amd64)armhf,和arm64体系结构上受支持
我们首先需要查看自己Ubuntu版本,使用一下代码
lsb_release -a
显示如下:
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS #16年3月发布的稳定版本,LTS是Long Term Support:长时间支持版本,支持周期长达三至五年
Release: 16.04 #发行日期或者是发行版本号
Codename: xenial #Ubuntu的代号名称
如果版本不一致,需安装Docker官方支持的版本。
$ sudo apt-get remove docker docker-engine docker.io containerd runc
此处出现如下报错:
Reading package lists… Error!
解决方法:
sudo rm /var/lib/apt/lists/* -vf
官方文档给了多种安装方法,本文使用存储库安装
1.更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
sudo apt-get update
sudo apt-get install \apt-transport-https \ca-certificates \curl \gnupg-agent \software-properties-common
2.添加Docker的官方GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
验证 key的 fingerprint 为 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.
sudo apt-key fingerprint 0EBFCD88
返回信息应该如下:
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <[email protected]>
sub 4096R/F273FCD8 2017-02-22
3.安装仓库
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
官方文档默认使用的国外镜像,安装非常慢,建议使用国内镜像安装:
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
再次更新
sudo apt-get update
安装
sudo apt-get install docker-ce docker-ce-cli containerd.io
测试当然是使用经典的helloworld!!!
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latest
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/
学习Docker一定要使用好Docker官方文档,如果按照本文方法按照出现问题,可以去官方文档看看,尝试找解决方法。