1 Star 0 Fork 83

hotsmile / install-docker

forked from Kenny小狼 / install-docker 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
install-docker.sh 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
KennyLee 提交于 2017-11-16 16:50 . 新增安装基础包
#! /bin/bash
##### Constants
DOCKER_LIB_HOME=/u01/lib/docker
STEP_COUNT=1
# YOUR_REGISTRY_MIRROR
DOCKER_REGISTRY_MIRROR="$1"
##### Functions
function command_installed(){
if [ -n "$1" ] && (type "$1" &> /dev/null ); then
return 0; # true
fi
return 1;
}
function service_started(){
if [ -n "$1" ]; then
info=$(systemctl status $1 | grep 'Active' )
read prefix status rest <<<"$info"
if [ $status == 'active' ]; then
return 0;
fi
fi
return 1;
}
function install_common_package(){
echo "########################"
echo " $STEP_COUNT. install common tools"
echo "########################"
if command_installed 'pip' && command_installed 'git' && command_installed 'iptables'; then
echo "common packages must be already installed."
else
yum makecache
yum install -y net-tools vim git \
ntsysv setuptool yum-utils python-pip python-setuptools \
lsof bzip2 unzip tar gcc wget nfs-utils
yum install -y policycoreutils-python
# install pip
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
rm -f get-pip.py
mkdir ~/.pip/
tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
fi
add_step_count
}
function install_docker_engine(){
docker_repo_file=/etc/yum.repos.d/docker.repo
docker_config_dir=/etc/systemd/system/docker.service.d
echo "########################"
echo " $STEP_COUNT. install docker engine"
echo "########################"
if command_installed 'docker'; then
echo "docker engine must be already installed."
else
tee $docker_repo_file <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/docker-engine/yum/gpg
EOF
yum makecache fast
yum -y install docker-engine
mkdir -p $docker_config_dir
if [ -n "$DOCKER_REGISTRY_MIRROR" ]; then
tee "$docker_config_dir/docker.conf" <<-EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd \
--graph=${DOCKER_LIB_HOME} \
--registry-mirror=${DOCKER_REGISTRY_MIRROR}
EOF
else
tee "$docker_config_dir/docker.conf" <<-EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd \
--graph=${DOCKER_LIB_HOME}
EOF
fi
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
# enable IPv4
sysctl -w net.ipv4.ip_forward=1
fi
add_step_count
}
function install_docker_compose(){
echo "########################"
echo " $STEP_COUNT. install Docker-Compose"
echo "########################"
if command_installed 'docker-compose'; then
echo "docker-compose must be already installed."
else
pip install docker-compose
fi
add_step_count
}
function install_supervisor(){
echo "########################"
echo " $STEP_COUNT. install Supervisor"
echo "########################"
if command_installed 'supervisord'; then
echo "supervisord must be already installed."
else
easy_install pip
pip install supervisor
fi
add_step_count
}
function add_step_count(){
((STEP_COUNT++))
}
function main(){
install_common_package
install_docker_engine
install_docker_compose
install_supervisor
}
main
Shell
1
https://gitee.com/hotsmile/install-docker.git
git@gitee.com:hotsmile/install-docker.git
hotsmile
install-docker
install-docker
master

搜索帮助