适合场景
- 无法访问外网的服务器环境
- 内网没有Docker软件源
- 需要离线安装Docker
- 使用rpm或deb等Docker安装包出现依赖地狱的情况,而实施人员无力解决
- 支持Systemd服务配置
- 支持多种架构:aarch64/armel/armhf/ppc64le/s390x/x86_64
官网地址:https://download.docker.com/linux/static/stable/x86_64/
根据架构选择目录,本文以x86_64举例

解压压缩包 tar -xvf docker-19.03.3-ce.tgz 将解压出的docker/bin目录下的可执行文件复制到/usr/bin cp docker/* /usr/bin/ 将docker注册为 Systemd 的 service cat > /etc/systemd/system/docker.service <<EOF [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 EOF 为 docker.service添加可执行权限 chmod +x /etc/systemd/system/docker.service 设置docker存储目录到大硬盘目录、设置私有镜像仓库地址(可选,注意替换目录位置与私有镜像仓库URL) mkdir /etc/docker mkdir -p /data1/docker #/data1是大硬盘目录 # 主要关注data-root的是最大硬盘目录存放docker容器系统相关的目录 # insecure-registries后边的值是私有镜像仓库地址,多个私有镜像仓库地址配置格式为["仓库1","仓库2"] # exec-opts部分针对于部署k8s做的预配置,可以减少容器日志保存大小及配合kubelet使用systemd cat > /etc/docker/daemon.json <<EOF { "insecure-registries":["10.2.41.191:5000"], "data-root":"/data1/docker", "exec-opts": ["native.cgroupdriver=cgroupfs"], "log-driver": "json-file", "log-opts": { "max-size": "20m" }, "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ] } EOF
{
"registry-mirrors": [
"https://docker-0.unsee.tech",
"https://docker-cf.registry.cyou",
"https://docker.1panel.live"
]
}
启动docker并设置开机自启
systemctl daemon-reload
systemctl enable --now docker.service
验证安装结果
systemctl status docker #查看docker服务状态
docker -v #查看docker版本
浙公网安备 33010602011771号