docker是做什么,就不用我来赘述,整个IT行业,docker使用频率一直在提高,任何一个新的软件安装部署对于一个新手来讲,都是比较麻烦的。下面提供一个脚本,即支持在线安装,也支持离线安装。特别提醒,如果是离线安装,则要提前下载docker和docker-compose安装文件。下载地址如下:
docker安装文件:https://download.docker.com/linux/static/stable/x86_64/
docker compose安装文件:https://github.com/docker/compose/releases
下载之后,把文件放到和脚本同一级目录即可。
[root@master184 docker]# ll
total 79364
-rw-r--r-- 1 root root 63673514 Dec 23 20:32 docker-19.03.8.tgz
-rw-r--r-- 1 root root 17586312 Dec 23 20:32 docker-compose-Linux-1.25.5-x86_64
-rw-r--r-- 1 root root 2471 Dec 23 20:32 install_docker.sh
如果想安装其他版本只需修改前面的几行脚本代码即可。
安装脚本如下:
#!/bin/bash
cd $(dirname $0)
DOCKER_FILE="docker-19.03.8.tgz"
COMPOSE_FILE="docker-compose-Linux-1.25.5-x86_64"
if [ ! -f ${DOCKER_FILE} ]; then
echo "Docker binary tgz files does not exist, please check it"
echo "Get docker binary from: https://download.docker.com/linux/static/stable/x86_64/"
echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/${DOCKER_FILE}"
exit 1
fi
if [ ! -f ${COMPOSE_FILE} ]; then
echo "Docker Compose binary tgz files does not exist, please check it"
echo "Get docker compose binary from: https://github.com/docker/compose/releases/download/1.25.5/"
echo "eg: wget https://github.com/docker/compose/releases/download/1.25.5/${COMPOSE_FILE}"
exit 1
fi
set -x
#本脚本为127.0.0.1执行
echo $(hostname -i) $(hostname) >> /etc/hosts
#setup
tar zxf ${DOCKER_FILE} && mv docker/* /usr/bin/ && rm -rf docker/
#systemd config
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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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
#start
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload && systemctl start docker && systemctl enable docker.service
#testing
docker -v
# 安装docker-compose
chmod 777 ${COMPOSE_FILE}
cp docker-compose-Linux-1.25.5-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -v