CentOS7 离线安装Docker&Docker Compose
说明:在内网环境下,无法在线安装docker和docker compose ,因此采用二进制包的方式离线安装docker和docker compose
1、下载docker和docker compose二进制包
从官网下载最新的docker包 docker-26.0.1.tgz
,下载地址:Index of linux/static/stable/x86_64/
从下载最新的docker compose包docker-compose-linux-x86_64
,下载地址:Releases · docker/compose · GitHub
2、上传二进制包至虚拟机内
# 新建docker文件夹
mkdir -p /user/local/docker
# 进入/user/local/docker目录,解压docker包
tar -xf ./docker-26.0.1.tgz
# 将解压出来的docker文件内容移动到 /usr/bin/ 目录下
cp ./docker/* /usr/local/bin/
# 查看docker版本
docker version
# 查看docker信息
docker info
# 添加daemon.json文件并编辑
vim /etc/docker/daemon.json
{
"bip": "10.233.0.1/22"
}
# 添加docker.service文件并编辑
vim /etc/systemd/system/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=10.0.66.6 #190.10.62.6 为docker私库镜像IP
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
# 添加文件可执行权限
chmod +x /etc/systemd/system/docker.service
# 重新加载配置文件
systemctl daemon-reload
# 启动Docker
systemctl start docker
# 重启Docker(修改相关配置文件后)
systemctl restart docker
# 查看docker启动状态(正常运行时:running)
systemctl status docker
# 查看启动容器
docker ps -a
# 设置开机自启动
systemctl enable docker.service
# 将docker-compose-xxxx文件名修改为docker-compose
# 将修改后地文件移动到 /usr/local/bin
cp ./docker-compose /usr/local/bin
# 添加权限
chmod +x /usr/local/bin/docker-compose
# 查看docker compose版本
docker-compose version