本文章只提供快速入门教程,旨在帮助新手们(包括我自己)快速入门一个相关知识,不包含详细的知识点以及高级的技术用法。如有需要,可自行查找更加详细的资料。
20分钟入门 - Docker教程
安装
博主的系统是Ubuntu 18.04.1
, 安装的是Docker19.03.6
, 如果是其他系统,或在想安装指定的Docker版本,可以参考Docker的官方教程。
删除旧版本Docker
Docker的就版本可能叫docker
、docker.io
、 或docker-engine
,在安装最新版之前必须将其删除,以免引起不必要的麻烦。
$ sudo apt-get remove docker docker-engine docker.io containerd runc
安装Docker Engine - Community
-
更新APT
$ sudo apt-get update
-
安装下面几个包,允许
apt
通过HTTPS使用仓库$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
-
添加官方的GPG密钥
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加完后验证是否添加正确
$ 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]
-
设置使用
stable
版本的仓库$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
-
安装
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
-
跑个"hello world"来验证一下是否安装正确
$ sudo docker run hello-world
如果你出现下面这种情况
Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout. See 'docker run --help'.
不要慌,再跑一次,你会发现神奇的事情发生。
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. ......
自此,安装完成?
什么?还是不行?
那你只能看看Docker的官方教程。注意你的系统,系统版本,需要安装的Docker版本。