通过阿里云的Docker CE镜像源站进行安装
一、使用官方安装脚本自动安装(仅适用于公网环境):
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
二、手动安装帮助(阿里云ECS可以通过内网安装):
1. 设置为阿里的镜像源并更新:
$ vim /etc/apt/sources.list
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security main
deb http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security universe
$ sudo apt-get update
2. 安装docker ce:
①. 官方Ubuntu存储库中提供的Docker安装包可能不是最新的版本.
②. 为了确保获得最新版本,从官方Docker存储库安装Docker.
③. 添加一个新的资源包,从Docker添加GPG密钥以确保下载有效,然后安装该包.
④. 推荐安装1.10.0以上版本的Docker客户端(docker-ce).
(1). 安装一些允许通过HTTPS才能使用的软件包:
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
(2). 安装GPG证书(将官方Docker存储库的GPG密钥添加到系统):
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
(3). 写入软件源信息(将Docker存储库添加到APT源):
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
(4). 检查安装是从Docker repo还是默认的Ubuntu repo:
apt-cache policy docker-ce
docker-ce:
Installed: (none)
Candidate: 18.03.1~ce~3-0~ubuntu
Version table:
18.03.1~ce~3-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
(5). 更新并安装Docker-CE:
①. 使用新添加的repo源中的Docker包更新包数据库
②. 指定版本安装:sudo apt-get -y install docker-ce=[VERSION]
sudo apt-get -y update
sudo apt install docker-ce
(6). 检查它是否正在运行:
sudo systemctl status docker
3. 配置镜像加速器:
通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://7cwrq8d9.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
三、检查与配置:
1. 安装校验:
docker version
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 07:52:04 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.0-ce
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 07:52:04 2017
OS/Arch: linux/amd64
Experimental: false
2. docker开启自启动:
开启自启动:
systemctl enable docker.service
docker启动:
systemctl start docker.service
四、docker-compose安装:
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose