1.环境要求:
docker安装环境:centos7及以上
kernel内核:3.10及以上
可使用下面命令查看
2.准备docker安装包和安装脚本
docker-18.06.3安装包
docker安装脚本
#!/bin/shusage(){ echo "使用方法: $0 FILE_NAME_DOCKER_CE_TAR_GZ" echo " $0 docker-18.06.3-ce.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-18.06.3-ce.tgz" echo ""}SYSTEMDDIR=/usr/lib/systemd/systemSERVICEFILE=docker.serviceDOCKERDIR=/usr/binDOCKERBIN=dockerSERVICENAME=dockerif [ $# -ne 1 ]; then usage exit 1else FILETARGZ="$1"fiif [ ! -f ${FILETARGZ} ]; then echo "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-18.06.3-ce.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": ["http://hub-mirror.c.163.com"]}EOFswapoff -aiptables -P FORWARD ACCEPTsysctl --systemsystemctl daemon-reloadsystemctl restart docker.serviceecho "## docker version"docker version
3.将docker安装脚本和安装包放在同一目录后执行安装脚本:
4.docker 启动情况确认
从上图可以看出docker服务能正常重启,其他命令自己可以尝试
5.如果正常的docker环境出现了乱七八糟的问题,可以先把/var/lib/docker备份后再执行上述1~4步骤,这样大部分问题都可以解决。