官网上安装docker,有两种方式,一种在线yum安装,另一种就是采用二进制离线安装。
0.检查本机环境
目前docker只支持centos7以上的版本
//查看自己的版本号
[root@aubin system]# uname -a
Linux aubin.com 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@aubin system]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
1.下载安装包
从官方网站上选一个适合的版本:https://download.docker.com/linux/static/stable/x86_64/
我选择的是最新版本:docker-20.10.8.tgz
2.安装
1.通过 FTP工具将 docker-20.10.8.tgz 上传到服务器上
2.解压安装包
tar -zxvf docker-20.10.8.tgz
3.将docker 相关命令拷贝到 /usr/bin,方便直接运行命令
sudo cp docker/* /usr/bin/
4.启动Docker守护程序
sudo dockerd &
5.验证是否安装成功,执行打印版本信息
docker version
3.把docker注册成服务
1.新增服务配置文件
$ vi /etc/systemd/system/docker.service
2.编辑服务配置文件
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
直接粘贴复制即可!直接粘贴复制即可!直接粘贴复制即可!
如上图所示,我上面粘贴完是这样的(第一行看着不全),我手贱把第一行补全,之后注册服务就报错了。
3.开启docker服务
$ systemctl enable docker
$ systemctl start docker
以上就安装完成了。
4.卸载docker
1.删除docker所安装的位置
[root@aubin docker]# whereis docker
docker: /usr/bin/docker /etc/docker
在安装过程中,我们将解压文件中的二进制文件拷贝到了/usr/bin/ 文件夹下了,我们将拷贝到该文件夹下的二进制文件删除。
2.删除docker相关文件和服务
删除/var/run/docer文件夹
删除/var/lib/docker文件夹
删除/var/run/docker.pid文件
删除/var/run/docker.sock文件
ps -aux | grep docker
停止docker相关进程
netstat -nplt | grep docker
解除docker相关进程占用端口