首先得拥有一台能上网的电脑下载离线包
1、安装 tar
如果 tar 命令不存在,需要安装,后面解压 Docker 需要用到。
将rpm安装包上传至目标服务器,执行安装命令:
rpm -Uvh tar-1.26-35.el7.x86_64.rpm --nodeps --force
2、安装Docker
Ⅰ.根据自己需求下载相应版本docker 离线安装包,下载地址:Docker 离线安装包
Ⅱ.将压缩包上传至目标服务器,我这里选择的是23.0.4版本,通过命令解压缩:
tar -zxvf docker-23.0.4.tgz
Ⅲ.复制文件
将docker中的全部文件复制到/usr/bin,执行命令:
cp ./docker/* /usr/bin
Ⅳ.创建docker.service文件
cd /etc/systemd/system/
touch docker.service
Ⅴ.编辑docker.service文件
vi docker.service
或
vim docker.service
将现有的docker.service内容清空,粘贴以下内容:
注意更改:
# 替换 --insecure-registry=192.168.0.100 IP地址
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=192.168.0.100
[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.205.230
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
保存并退出:
!wq
Ⅵ.添加执行权限
chmod +x docker.service
Ⅶ.加载 docker.service
systemctl daemon-reload
Ⅷ.启动 docker
systemctl start docker
Ⅸ.查看 docker 状态
systemctl status docker
Ⅹ.查看 docker 版本信息
docker -v
Ⅺ.设置开机启动
systemctl enable docker.service
3、安装脚本(可选)
创建 docker.service 跟前面一样,注意替换 IP。
touch install.sh
或
vi install.sh
或
vim 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
卸载脚本:
#!/bin/sh
echo '停止docker'
systemctl stop docker
echo '删除docker.service'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功'
文章评论