安装docker:
首先查看linux的内核
root@peppaPig:~# uname -r
4.15.0-52-generic
Docker 要求操作系统必须为64位,且Linux内核版本为3.1及以上
1.更新必要的一些系统工具
root@peppaPig:~# apt-get update
root@peppaPig:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common
2.安装GPG证书
root@peppaPig:~# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
#执行结果
ok
3. 写入软件源信息
root@peppaPig:~# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
4.更新并安装 Docker-CE
root@peppaPig:~# apt-get -y update
root@peppaPig:~# apt-get -y install docker-ce
附:在执行apt-get -y install docker-ce之前,还可以选择安装指定版本的Docker-CE:
1).查找Docker-CE的版本:
root@peppaPig:~# apt-cache madison docker-ce
docker-ce | 5:19.03.8~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.7~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.6~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.5~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.4~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.3~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.2~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.1~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.0~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.9~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.8~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.7~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.6~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.5~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.4~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.3~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.2~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.1~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.0~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 18.06.3~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 18.06.2~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 18.06.1~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 18.06.0~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 18.03.1~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
root@peppaPig:~#
2).安装指定版本的Docker-CE:
root@peppaPig:~# apt-get -y install docker-ce=[18.03.1~ce~3-0~ubuntu]
不过我选择的是 默认安装。
6.查看docker信息:
root@peppaPig:~# docker --version
Docker version 19.03.8, build afacb8b7f0
卸载:
1.执行删除命令:
root@peppaPig:~# apt-get remove docker
2.因为安装的是docker-ce所以还要删除 docker-ce,
root@peppaPig:~# apt-get remove docker-ce
3.执行docker --version,验证是否卸载成功:
root@peppaPig:~# docker --version
Docker version 19.03.8, build afacb8b7f0
4.如果出现上面情况说明卸载没有成功,可以通过下面方法继续卸载:
root@peppaPig:~# apt-get remove docker*
5.再次执行docker --version
root@peppaPig:~# docker --version
Command 'docker' not found, but can be installed with:
apt install docker.io
出现上面情况说明docker已经卸载完成。
如果想卸载干净,还可以执行:
root@peppaPig:~# dpkg -l | grep docker
rc docker 1.5-1build1 amd64 System tray for KDE3/GNOME2 docklet applications
rc docker-ce 5:19.03.8~3-0~ubuntu-bionic amd64 Docker: the open-source application container engine
rc docker.io 1.6.2~dfsg1-1ubuntu4~14.04.1 amd64 Linux container runtime
root@peppaPig:~# apt remove --purge dock*
至此,docker的安装与卸载就全部完成。