#!/bin/bash
# 该脚本基于 Ubuntu 16.04 64位 操作系统
# 设置主机名
echo ‘docker-lab‘ >/etc/hostname
hostname docker-lab
# 配置Ubuntu源
cat >/etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
EOF
# 配置docker源(使用阿里云镜像站)
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
#add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
# 安装docker
apt-get -y install docker-ce
# 配置docker加速器(https://www.daocloud.io/mirror)(https://www.daocloud.io/mirror),下面的加速链接已做加密处理,请自行申请自己的加速链接
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6c4b02a7.m.daocloud.io
systemctl restart docker.service
# 测试docker是否安装成功
echo ‘\n-------------------------------------------------------------------------------\n\t\t\t运行 hello-world 测试Docker是否安装成功\n-------------------------------------------------------------------------------\n\n‘
docker run hello-world