参考自这里

1 安装docker

查看发行情况:lsb_release -a,返回如下:

Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic

其中bionic就是代号。下面以官方代码库的方式安装,也可以直接从ubuntu的repository里直接安装。

  • 安装必要的环境:

sudo apt-get install apt-transport-https ca-certificates

  • 添加GPG key,某些docker包需要这个加密(废的)

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

  • 添加相关的站点到docker列表(废的)

echo "deb https://apt.dockerproject.org/repo ubuntu-bionic main" | sudo tee /etc/apt/sources.list.d/docker.list

后来发现这个源有误,只要删除文件sudo rm -f /etc/apt/sources.list.d/docker.list再执行更新sudo apt-get update即可, 如果还不行,编辑一下文件:/etc/apt/sources.list

靠谱的办法是,参考自这里

(1)添加gpg key:curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

(2)添加源:sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable", 上述源文件末尾会新增一行。

  • 安装最新ce版 sudo apt-get install docker-ce,有几百M

验证:sudo docker version,内容如下:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:25:46 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 01:24:19 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

2