为CentOS&Ubuntu安装Docker-CE

在CentOS7和Ubuntu中安装docker-ce

CentOS 7

1
2
3
4
5
6
$ yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ yum makecache fast
$ yum -y install docker-ce
$ service docker start
$ systemctl enable docker 

Ubuntu 18.04

1
2
3
4
5
6
7
8
$ curl -s http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
$ cat <<EOF >/etc/apt/sources.list.d/docker-ce.list
deb [arch=amd64] https://mirror.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu xenial stable
EOF
$ apt-get update
$ apt-get install -y docker-ce
$ service docker start
$ systemctl enable docker

修改国内源

1
2
3
4
5
6
7
8
9
10
11
$ cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF