Docker在Centos7离线安装

下载 Docker 二进制文件(离线安装包)

下载地址:https://download.docker.com/linux/static/stable/x86_64/

注:本文使用 /x86_64/docker-18.06.1-ce.tgz,注意对应操作系统类型。

tar tf docker-20.10.9.tgz

docker/
docker/containerd-shim-runc-v2
docker/dockerd
docker/docker-proxy
docker/ctr
docker/docker
docker/runc
docker/containerd-shim
docker/docker-init
docker/containerd
tar zxf docker-18.06.1-ce.tgz
sudo cp docker/* /usr/bin/
sudo dockerd &

验证是否安装成功,执行docker info命令

docker info

注册成系统服务

/etc/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket

[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 -H fd:// -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
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=20
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

/etc/systemd/system/docker.socket

[Unit]
Description=Docker Socket for the API
PartOf=docker.service

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

启用

注意:没有docker用户组docker.socket服务启动报错

sudo groupadd docker
usermod -aG docker $USER
systemctl daemon-reload

修改docker配置

/etc/docker/daemon.json

{
  "insecure-registries": ["127.0.0.1:5001", "harbor.cn"],
  "bip": "172.18.18.1/24",
  "data-root": "/var/lib/docker",
  "storage-driver": "overlay2",
  "live-restore": true,
  "log-opts": {
    "max-size": "500m"
  }
}

修改host文件

#BEGIN --generated by Harbor
172.16.1.114 harbor.cn