centos下
#!/bin/bash
initDocker() {
echo "========== initDocker =========="
if ! which docker; then
echo "安装 docker"
sudo yum -y install yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast #更新缓存
sudo yum -y install docker-ce #安装软件包
sudo systemctl start docker #启动
sudo systemctl enable docker #开机启动
sudo systemctl is-enabled docker #检查开机状态
sudo docker version #检查docker版本
fi
if ! which docker-compose; then
echo "安装 docker-compose"
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
fi
}
initDocker
ubuntu
#!/bin/bash
updateSourceList() {
echo "========== updateSourceList =========="
if ! cat /etc/apt/sources.list | grep 'aliyun.com' >/dev/null; then
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
apt-get update
fi
}
initDocker() {
echo "========== initDocker =========="
if ! which docker; then
echo "安装 docker"
sudo apt-get purge -y docker-ce
sudo apt-get purge -y docker-ee
sudo rm -rf /var/lib/docker
sudo apt-get -y install docker.io
fi
if ! which docker-compose; then
echo "安装 docker-compose"
sudo apt-get install -y -qq docker-compose
fi
}
updateSourceList
initDocker
网友评论