Docker离线安装部署
1.杀死docker有关的容器:
docker kill $(docker ps -a -q)
2.删除所有docker容器:
docker rm $(docker ps -a -q)
3.删除所有docker镜像:
docker rmi $(docker images -q)
4.停止 docker 服务:
systemctl stop docker
5.删除docker相关存储目录:(分别进行执行以下四个命令)
rm -rf /etc/docker
rm -rf /run/docker
rm -rf /var/lib/dockershim
rm -rf /var/lib/docker
6.如果删除不掉,则先umount:
umount /var/lib/docker/devicemapper
7.然后再重新执行上面那步“删除docker相关存储目录”。
二、卸载工作
经过上面一系列准备后,我们终于到了最后环节,开始删除docker。
1.查看系统已经安装了哪些docker包:
[root@localhost ~]# yum list installed | grep docker
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
containerd.io.x86_64 1.4.12-3.1.el7 @docker-ce-stable
docker-ce.x86_64 3:20.10.11-3.el7 @docker-ce-stable
docker-ce-cli.x86_64 1:20.10.11-3.el7 @docker-ce-stable
docker-ce-rootless-extras.x86_64 20.10.11-3.el7 @docker-ce-stable
docker-scan-plugin.x86_64 0.9.0-3.el7 @docker-ce-stable
卸载相关包:
[root@localhost ~]# yum remove containerd.io.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64 docker-ce-rootless-extras.x86_64 docker-scan-plugin.x86_64
2.接着会出现选择提示,直接输入“y”然后回车就可以。
3.再次查看
yum list installed | grep docker
不再出现相关信息,证明删除成功,
4.再看看docker命令:
[root@localhost ~]# docker version
-bash: /usr/bin/docker: 没有那个文件或目录
离线安装部署
一、准备工作
docker安装包下载地址:https://download.docker.com/linux/static/stable/x86_64/
二、创建系统配置文件
创建文件:
vi /opt/docker/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
三、创建安装脚本
vi /opt/docker/install.sh
内容如下:
#!/bin/sh
echo '解压tar包...'
tar -xvf $1
echo '将docker目录移到/usr/bin目录下...'
cp docker/* /usr/bin/
echo '将docker.service 移到/etc/systemd/system/ 目录...'
cp docker.service /etc/systemd/system/
echo '添加文件权限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
systemctl daemon-reload
echo '启动docker...'
systemctl start docker
echo '设置开机自启...'
systemctl enable docker.service
echo 'docker安装成功...'
docker -v
四、创建卸载脚本
vi /opt/docker/uninstall.sh
内容如下:
#!/bin/sh
echo '删除docker.service...'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件...'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功...'
安装
sh install.sh docker-20.10.9.tgz
配置国内源
编辑daemon.josn
vi /etc/docker/daemon.json
配置国内源地址
{
"registry-mirrors" : [
"https://mirror.ccs.tencentyun.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}
重启docker
systemctl restart docker.service
查看结果
##查看状态
systemctl status docker
##查看版本号
docker version