前言:
有些特殊情况,服务器是在内网的无法连接外网安装Docker和docker-compose。Docker官网也是提供了离线安装模式。
根据不同的系统有环境要求,这块可以参考Docker官网 https://docs.docker.com/engine/install/
Docker安装
环境要求:
1、centos7以上(包含centos7)
2、kernel内核:3.10及以上 查看命令 uname -r
离线安装包:
1、准备docker安装包和安装脚本
Docker官方下载地址:https://download.docker.com/linux/static/stable/x86_64/
或者选择阿里云镜像站下载 https://mirrors.aliyun.com//docker-ce/linux/static/stable/x86_64/
根据自己的需要进行下载,这块我选择最新的docker-20.10.5.tgz
2、Docker安装脚本
创建install-docker.sh脚本:
#!/bin/shusage(){echo "使用方法: $0 FILE_NAME_DOCKER_CE_TAR_GZ"echo " $0 docker-20.10.5.tgz"echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz"echo ""}SYSTEMDDIR=/usr/lib/systemd/systemSERVICEFILE=docker.serviceDOCKERDIR=/usr/binDOCKERBIN=dockerSERVICENAME=dockerif [ $# -ne 1 ]; thenusageexit 1elseFILETARGZ="$1"fiif [ ! -f ${FILETARGZ} ]; thenecho "Docker binary tgz files does not exist, please check it"echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz"exit 1fiecho "##unzip : tar xvpf ${FILETARGZ}"tar xvpf ${FILETARGZ}echoecho "##binary : ${DOCKERBIN} copy to ${DOCKERDIR}"cp -p ${DOCKERBIN}/* ${DOCKERDIR} >/dev/null 2>&1which ${DOCKERBIN}echo "##systemd service: ${SERVICEFILE}"echo "##docker.service: create docker systemd file"cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF[Unit]Description=Docker Application Container EngineDocumentation=http://docs.docker.comAfter=network.target docker.socket[Service]Type=notifyEnvironmentFile=-/run/flannel/dockerWorkingDirectory=/usr/local/binExecStart=/usr/bin/dockerd \-H tcp://0.0.0.0:4243 \-H unix:///var/run/docker.sock \--selinux-enabled=false \--log-opt max-size=1gExecReload=/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=infinityLimitNPROC=infinityLimitCORE=infinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMax=infinityTimeoutStartSec=0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=processRestart=on-failure[Install]WantedBy=multi-user.targetEOFecho ""systemctl daemon-reloadecho "##Service status: ${SERVICENAME}"systemctl status ${SERVICENAME}echo "##Service restart: ${SERVICENAME}"systemctl restart ${SERVICENAME}echo "##Service status: ${SERVICENAME}"systemctl status ${SERVICENAME}echo "##Service enabled: ${SERVICENAME}"systemctl enable ${SERVICENAME}cat >/etc/docker/daemon.json <<EOF{"registry-mirrors": ["https://bn4ll166.mirror.aliyuncs.com"],"data-root": "/data/docker-root","dns": ["223.5.5.5", "119.29.29.29"],"bip": "172.31.255.254/16","storage-driver": "overlay2","storage-opts": ["overlay2.override_kernel_check=true"],"userland-proxy": false,"log-driver": "json-file","log-opts": {"max-size": "50m","max-file": "1"}}EOFswapoff -aiptables -P FORWARD ACCEPTsysctl --systemsystemctl daemon-reloadsystemctl restart docker.serviceecho "## docker version"docker version
授权install-docker.sh为可以执行脚本,chmod +x install-docker.sh
3、执行install-docker.sh脚本,进行安装docker

版本号打印
安装成功
