一、CentOS7离线安装 Docker 步骤
1、docker 安装包下载地址
2、将下载的 docker-18.06.3-ce.tgz 文件上传到 Centos7 服务器上(如上传到 /home/docker 目录下),并执行 tar 命令解压,如下图:
tar -zxvf docker-18.06.3-ce.tgz
3、将/home/docker 目录下解压出来的所有 docker 文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
4、将 docker 注册为 service,进入/etc/systemd/system/目录,并创建 docker.service 文件
cd /etc/systemd/system/
touch docker.service
5、编辑 docker.service 文件,将以下内容复制到 docker.service 文件中
- 注:以下内容中 --insecure-registry=192.168.3.10 此处改为你自己服务器 ip
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 --selinux-enabled=false --insecure-registry=192.168.3.10
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
6、给 docker.service 文件添加执行权限
chmod 777 /etc/systemd/system/docker.service
7、重新加载配置文件
- 注:每次修改 docker.service 这个文件时都要重新加载下。
systemctl daemon-reload
8、启动 Docker 服务
systemctl start docker
9、设置开机启动 Docker 服务
systemctl enable docker.service
10、验证 docker 是否启动成功
- 查看 Docker 状态,显示 active(running)表示启动成功
systemctl status docker
- 查看 Docker 版本
docker -v
11、配置镜像加速器,默认是到国外拉取镜像速度慢,如下图:
- 编辑 /etc/docker/目录下的 daemon.json 文件,将以下内容复制到 daemon.json 文件中
vim /etc/docker/daemon.json
{"registry-mirrors": ["http://hub-mirror.c.163.com"]}
- 重启 docker,使其 daemon.json 文件配置生效
service docker restart
二、CentOS7 离线卸载Docker步骤
1、删除服务
取消开机自启
systemctl disable docker
取消注册文件
rm -rf /etc/systemd/system/docker.service
2、删除命令
rm -rf /usr/bin/containerd
rm -rf /usr/bin/containerd-shim
rm -rf /usr/bin/ctr
rm -rf /usr/bin/runc
rm -rf /usr/bin/docker*
3、删除配置
rm -rf /etc/docker/
4、删除镜像或容器
rm -rf /var/lib/docker