Ubuntu20.04安装与卸载Docker-ce
docker版本介绍
- Docker CE 在 17.03 版本之前叫 Docker Engine, Docker Engine 的版本号范围: 0.1.0 ~ 1.13.1 在 2017 年 3 月 2 日, docker 团队宣布企业版 Docker Enterprise Edition ( EE ) 发布. 为 了一致, 免费的 Docker Engine 改名为 Docker Community Edition ( CE ), 并且采用基于 时间的版本号方案. 就在这一天, Docker EE 和 Docker CE 的 17.03 版本发布, 这也是第一 个采用新的版本号方案的版本. Docker CE/EE 每个季度发布一次 季度版本, 也就是说每年会发布 4 个季度版本, 17.03, 17.06, 17.09, 17.12 就是 2017 年的 4 个季度版本的版本号, 同时 Docker CE 每个月还会 发布一个 EDGE 版本,比如 17.04, 17.05, 17.07, 17.08, 17.10, 17.11 … Docker CE 季度版本自发布后会有 4 个月的维护期. 在基于时间的发布方案中,版本号格式为: YY.MM.,YY.MM 代表年月,patch 代表补丁 号,从 0 开始,在季度版本 (如 17.03) 的维护期内,bug 修复相关的更新会以 patch 递 增的方式发布, 比如 17.03.0 -> 17.03.1 -> 17.03.2
- docker.io是很早之前的版本,Ubuntu系统一般默认安装的是docker-ce,就是docker的社区版本。
- docker-io, docker-ce, docker-ee 区别
自动安装
官方安装脚本自动安装
-
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
daocloud脚本自动安装
-
curl -sSL https://get.daocloud.io/docker | sh
手动安装
-
卸载旧版本的docker,docker的旧版本成为docker docker.io 或者 docker-engine,如果安装的有旧版本的docker,卸载它们:
sudo apt-get remove docker docker-engine docker.io containerd runc
社区版本的docker成为docker-ce,在Ubuntu系统上安装社区版,介绍两种方式:
使用Docker仓库进行安装
-
在新主机上面安装docker之前需要先设置docker仓库,之后可使用仓库安装和更新Docker
-
设置仓库
-
更新apt索引
apt-get update
-
安装apt依赖包,用于通过https来获取仓库
apt-get install \ apt-transport-https \ ca--certificates \ curl \ gnupg-agent \ software-properties-common
-
添加docker官方GPG密钥
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - >>> OK
-
59DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 通过搜索指纹的后8个字符,验证现在是否拥有带有指纹的密钥.
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]
-
使用以下指令设置稳定版仓库。
sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable"
-
-
安装社区版本docker
-
更新apt索引
sudo apt-get update
-
输入下列命令安装最新版本的docker-ce和containerd,或者跳转下一步安装指定版本的docker-ce。
sudo apt-get insall docker-ce docker-ce-cli containerd.io
-
要安装特定版本的 Docker Engine-Community,请在仓库中列出可用版本,然后选择一种安装。列出您的仓库中可用的版本:
apt-cache madison docker-ce >>> docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages
使用第二列中的版本字符串安装特定版本,例如 5:18.09.13-0ubuntu-xenial。
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
-
-
测试docker是否安装成功,输入以下指令,打印出下列信息则成功:
sudo docker run hello-world >>> Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f 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/
输出内容也有可能是:
Unable to find image 'hell-world:latest' locally docker: Error response from daemon: pull access denied for hell-world, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'.
此时在命令行输入:
docker
如果输出下列内容也可证明docker安装成功:
Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit ...
卸载docker
-
删除安装包:
sudo apt-get purge docker-ce
-
删除镜像、容器、配置文件等:
sudo rm -rf /var/lib/docker
启动docker
-
输入命令:
service docker start
检查是否成功启动:
service docker status
如果输出下列内容,证明成功启动:
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2021-12-18 16:48:31 CST; 4min 38s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 21528 (dockerd) Tasks: 8 Memory: 30.9M CGroup: /system.slice/docker.service └─21528 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.746148676+08:00" level=warning msg="Your kernel doe> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.746387961+08:00" level=info msg="Loading containers> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.887471558+08:00" level=info msg="Default bridge (do> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.949525729+08:00" level=info msg="Loading containers> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.964411217+08:00" level=info msg="Docker daemon" com> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.964725560+08:00" level=info msg="Daemon has complet> Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ systemd[1]: Started Docker Application Container Engine. Dec 18 16:48:31 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:48:31.995242396+08:00" level=info msg="API listen on /run> Dec 18 16:49:03 iZ8vbisc62tb8ctiz9o7oyZ dockerd[21528]: time="2021-12-18T16:49:03.298360933+08:00" level=error msg="Not continuing wi>