Docker 实际使用时,我们的虚拟机、服务器可能不能联网,此时就需要在离线的情况下安装Docker。
1、Docker安装包下载并上传
选择需要安装的版本,点击即可下载
我下载的是(当前最新):docker-20.10.1.tgz
2、创建系统配置文件 docker.service
在Docker安装包同级目录创建docker.service
vim docker.service
[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安装包同级目录创建install.sh和uninstall.sh
安装脚本 install.sh
# 创建安装脚本
vim install.sh
#!/bin/sh
echo '解压tar包...'
sudo tar -zxvf $1
echo '将docker目录移到/usr/bin目录下...'
sudo cp docker/* /usr/bin/
echo '将docker.service 移到/etc/systemd/system/ 目录...'
sudo cp docker.service /etc/systemd/system/
echo '添加文件权限...'
sudo chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
sudo systemctl daemon-reload
echo '启动docker...'
sudo systemctl start docker
echo '设置开机自启...'
sudo systemctl enable docker.service
echo 'docker安装成功...'
sudo docker -v
# 保存后授权
chmod +x ./install.sh
卸载脚本 uninstall.sh
# 创建卸载脚本
vim uninstall.sh
#!/bin/sh
echo '删除docker.service...'
sudo rm -f /etc/systemd/system/docker.service
echo '删除docker文件...'
sudo rm -rf /usr/bin/docker*
echo '重新加载配置文件'
sudo systemctl daemon-reload
echo '卸载成功...'
# 保存后授权
chmod +x ./uninstall.sh
4、安装Docker
进入安装包目录
执行命令:./install.sh docker-20.10.1.tgz
等待安装成功即可,最后会打印docker的版本信息
5、卸载Docker
进入安装包目录,执行命令:./uninstall.sh
等待输出 “卸载成功...”即可,
并使用 docker -v 命令查看