Centos7安装Docker环境
# 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 设置yum源(选择其中一个)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
# 查看yum 源上docker版本
yum list docker-ce --showduplicates | sort -r
# 安装需要的版本
yum install docker-ce-18.03.1.ce
启动服务
systemctl start docker
systemctl enable docker
Ubuntu 16.04安装docker
#由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本:
sudo apt-get remove docker docker-engine docker-ce docker.io
#更新apt包索引:
sudo apt-get update
#安装以下包以使apt可以通过HTTPS使用存储库(repository):
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
#添加Docker官方的GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#使用下面的命令来设置stable存储库:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
#再更新一下apt包索引:
sudo apt-get update
#安装最新版本的Docker CE:
sudo apt-get install -y docker-ce
#查看docker服务是否启动:
sudo systemctl status docker
#若未启动,则启动docker服务:
sudo systemctl start docker
Docker 脚本安装
#!/bin/bash
docker_software="docker-19.03.9"
docker_download_link="https://download.docker.com/linux/static/stable/x86_64/"
docker_service="/usr/lib/systemd/system/docker.service"
registry_mirrors="https://7hsct51i.mirror.aliyuncs.com"
docker_dir_base="/data/docker"
docker_dir_bin="${docker_dir_base}/bin"
docker_dir_conf="${docker_dir_base}/conf"
docker_dir_data="${docker_dir_base}/data"
# 如下自动执行
mkdir -p ${docker_dir_bin}
mkdir -p ${docker_dir_conf}
mkdir -p ${docker_dir_data}
# 安装wget
rpm -q wget > /dev/null 2>&1
if [ "$?" -ge 1 ];then
echo "install wget,Please wait..."
yum -y install wget > /dev/null 2>&1
rpm -q wget > /dev/null 2>&1
[ $? -ge 1 ] && echo "wget installation failure,exit" && exit
echo "安装wget 成功"
fi
# 下载软件包并解压
if [ ! -f ${docker_software}.tgz ];then
echo "正在下载安装包:${docker_software}.tgz"
wget ${docker_download_link}${docker_software}.tgz
[ ! -f ${docker_software}.tgz ] && echo "${docker_software}.tgz download failure,exit" && exit
else
echo "安装包已存在:${docker_software}.tgz"
fi
mkdir -p ${docker_dir_bin}
tar zxvf ${docker_software}.tgz -C ${docker_dir_base} > /dev/null 2>&1
if [ "$?" != 0 ];then
echo "${docker_software}.tgz 解压失败,退出程序" && exit
fi
mv -f ${docker_dir_base}/docker/* ${docker_dir_bin} > /dev/null 2>&1
find ${docker_dir_bin} -type f | xargs -i ln -sfn {} /usr/local/bin/
echo "${docker_software}.tgz下载解压完成"
# Sytemctl 管理
cat > ${docker_service} << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
ExecStart=${docker_dir_bin}/dockerd \
--config-file ${docker_dir_conf}/daemon.json \
--data-root ${docker_dir_data} \
-H tcp://0.0.0.0:8088 -H unix:///var/run/docker.sock
ExecReload=/bin/kill -s HUP \$MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
echo "Sytemctl 管理配置完成:${docker_service}"
# 镜像加速
mkdir -p ${docker_dir_conf}
cat > ${docker_dir_conf}/daemon.json << EOF
{
"registry-mirrors": ["${registry_mirrors}"]
}
EOF
echo "镜像加速配置完成:${docker_dir_conf}/daemon.json"
# 启动docker
systemctl daemon-reload
systemctl restart docker.service
# 开机启动
echo "配置开机启动"
systemctl enable docker
echo "测试docker,运行容器:hello-world"
docker run hello-world
clear
cat << EOF
${docker_software} 版本,成功安装
相关信息:
base docker安装目录:${docker_dir_base}
bin 执行文件目录:${docker_dir_bin}
conf 配置文件目录:${docker_dir_conf}
data 数据存储目录:${docker_dir_data}
EOF
Docker-Compose 二进制脚本安装
#!/bin/bash
docker_compose='docker-compose'
# 下载软件包并解压
if [ ! -f ${docker_compose}* ];then
echo "正在下载安装包:${docker_compose}"
curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64 -o ./${docker_compose}
[ ! -f ${docker_compose}* ] && echo "${docker_compose} download failure,exit" && exit
else
echo "安装包已存在:${docker_compose}"
fi
chmod 777 ${docker_compose}
mv -f ${docker_compose} /usr/local/bin
${docker_compose}
if [ "$?" -eq 0 ];then
clear && echo "安装${docker_compose}成功"
fi
docker-compose