1.2 Docker安装及基础命令介绍

1.2.1 Docker安装准备

官方网址:https://www.docker.com/

OS系统版本选择:
Docker目前已经支持多种操作系统的安装运行,比如Ubuntu、CentOS、Redhat、Debian、Fedora,甚至是还支持了Mac和Windows,在linux系统上需要内核版本在3.10或以上

Docker版本选择:
docker版本号之前一直是0.X版本或1.X版本,但是从2017年3月1号开始改为每个季度发布一次稳定版,其版本号规则也统一变更为YY.MM,例如17.09表示是2017年9月份发布的

Docker之前没有区分版本,但是2017年推出(将docker更名为)新的项目Moby,github地址:https://github.com/moby/moby,Moby项目属于Docker项目的全新上游,Docker将是一个隶属于的Moby的子产品,而且之后的版本之后开始区分为CE (Docker Community Edition,社区版本) 和EE (Docker Enterprise Edition,企业收费版),CE社区版本和EE企业版本都是每个季度发布一个新版本,但是EE版本提供后期安全维护1年,而CE版本是4个月,以下为官方原文:

https://www.docker.com/blog/docker-enterprise-edition/

Docker CE and EE are released quarterly, and CE also has a monthly “Edge” option. Each Docker EE release is supported and maintained for one year and receives security and critical bugfixes during that period. We are also improving Docker CE maintainability by maintaining each quarterly CE release for 4 months. That gets Docker CE users a new 1-month window to update from one version to the next.

如果要布署到kubernets上,需要查看相关kubernets对docker版本要求的说明,比如:

https://github.com/kubernetes/kubernetes/blob/v1.17.2/CHANGELOG-1.17.md

1.2.2 安装和删除方法

官方文档:https://docs.docker.com/engine/install/

阿里云文档:https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11guHCWE

1.2.2.1 Ubuntu安装和删除Docker

官方文档:https://docs.docker.com/engine/install/ubuntu/

Ubuntu 14.04/176.04/18.04安装docker

# step1:安装必要的一些系统工具
[root@ubuntu1804 ~]# apt update
[root@ubuntu1804 ~]# apt install apt-transport-https ca-certificates curl software-properties-common -y
# step2: 安装GPG证书
[root@ubuntu1804 ~]# curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | apt-key add -
OK
# step3:写入软件源信息
[root@ubuntu1804 ~]# add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# step4:更新并安装Docker-CE
[root@ubuntu1804 ~]# apt update -y
[root@ubuntu1804 ~]# apt install docker-ce -y

# 安装指定版本的Docker-CE
# step1: 查找Docekr-CE版本:
[root@ubuntu1804 ~]# apt-cache madison docker-ce
 docker-ce | 5:20.10.7~3-0~ubuntu-bionic | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.6~3-0~ubuntu-bionic | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic/stable amd64 Packages
...省略...
 docker-ce | 18.06.0~ce~3-0~ubuntu | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.03.1~ce~3-0~ubuntu | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic/stable amd64 Packages

# step2: 安装指定版本的docker-ce:(VERSION例如上边的5:20.10.6~3-0~ubuntu-hirsute)
apt install docker-ce=[version] docker-ce-cli=[verison]
# 示例:指定版本安装
[root@ubuntu1804 ~]# apt install docker-ce=5:19.03.15~3-0~ubuntu-bionic docker-ce-cli=5:19.03.15~3-0~ubuntu-bionic -y

Ubuntu 2104安装docker

# step1:安装必要的一些系统工具
[root@ubuntu2104 ~]# apt update
[root@ubuntu2104 ~]# apt install apt-transport-https ca-certificates curl software-properties-common -y
# step2: 安装GPG证书
[root@ubuntu2104 ~]# curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
# step3:写入软件源信息
[root@ubuntu2104 ~]# add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# step4:更新并安装Docker-CE
[root@ubuntu2104 ~]# apt update -y
[root@ubuntu2104 ~]# apt install docker-ce -y

# 安装指定版本的Docker-CE
# step1: 查找Docekr-CE版本:
[root@ubuntu2104 ~]# apt-cache madison docker-ce
 docker-ce | 5:20.10.7~3-0~ubuntu-hirsute | https://mirrors.aliyun.com/docker-ce/linux/ubuntu hirsute/stable amd64 Packages
 docker-ce | 5:20.10.6~3-0~ubuntu-hirsute | https://mirrors.aliyun.com/docker-ce/linux/ubuntu hirsute/stable amd64 Packages

# step2: 安装指定版本的docker-ce:(VERSION例如上边的5:20.10.6~3-0~ubuntu-hirsute)
apt install docker-ce=[version] docker-ce-cli=[verison]
# 示例:指定版本安装
[root@ubuntu2104 ~]# apt install docker-ce=5:20.10.6~3-0~ubuntu-hirsute docker-ce-cli=5:20.10.6~3-0~ubuntu-hirsute -y

删除docker

[root@ubuntu1804 ~]# apt purge docker-ce -y
[root@ubuntu1804 ~]# rm -rf /var/lib/docker/