今天尝试安装docker,通过官网教程运行

$ sudo apt-get update

然后就报错了……

错误:5 https://download.docker.com/linux/ubuntu focal InRelease
  由于没有公钥,无法验证下列签名: NO_PUBKEY 7EA0A9C3F273FCD8

通过大量的尝试,发现需要自己添加公钥

#把提示的最后8位复制过来即可
$ sudo apt-key adv --recv-keys --keyserver keyserver.Ubuntu.com F273FCD8 

然后安装一系列的包

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

接着

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

这里又报错了……

curl: (77) error setting certificate verify locations:
  CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs

这个ca_certificates.crt文件有问题,从http://curl.haxx.se/ca/cacert.pem下载cacert.pem替换掉。

$ sudo cp /home/lif/桌面/cacert.pem /etc/ssl/certs/ca-certificates.crt

然后重新下载docker证书,成功,可以通过查看公钥来验证

$ sudo apt-key fingerprint 0EBFCD88

#如果提示如下 说明成功
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

接下来设置docker的库,我选的是stable版的

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

然后安装docker:

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

安装完成后,通过docker helloworld test 来测试是否安装成功!

$ sudo docker run hello-world

成功示例:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
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/

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐