安装
- 系统:Ubuntu 16.04 LTS
## 准备工作
- 确保安装curl
查询
```
whereis curl
```
安装
```
sudo apt install curl
```
- 可能需要升级apt-get
```
sudo apt-get update
```
遇到问题一个一个解决
## 脚本自动安装docker
- 官方一套安装脚本,Ubuntu 和 Debian 系统适用(推荐)
```
curl -sSL https://get.docker.com/ | sh
```
- 如果官方被墙,阿里云的安装脚本
```
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/
docker-engine/internet | sh -
```
- 如果官方被墙,DaoCloud 的安装脚本
```
curl -sSL https://get.daocloud.io/docker | sh
```
安装完成后有个提示:
```
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker runoob
Remember that you will have to log out and back in for this to take effect!
```
> 当要以非root用户可以直接运行docker时,需要执行 sudo usermod -aG docker zhaohongwei 命令,然后重新登陆,否则会有报错
## 启动docker 后台服务
```
sudo service docker start
```
## 测试运行hello-world
```
docker run hello-world
```
# 镜像加速器
## 配置
国内访问 Docker Hub 有时会遇到困难,使用docker pull 获取镜像超时,此时可以配置镜像加速器。国内很多云服
务商都提供了加速器服务,例如:
[阿里云加速器](https://cr.console.aliyun.com/#/accelerator)
[DaoCloud 加速器](https://www.daocloud.io/mirror#accelerator-doc)
> 注册用户并且申请加速器,会获得如
https://jxus37ad.mirror.aliyuncs.com 这样的地址。我们需要将其配置给
Docker 引擎。
Ubuntu 16.04、Debian 8 Jessie、CentOS 7配置加速器.
对于使用 systemd 的系统,用 systemctl enable docker 启用服务后,编辑
```
/etc/systemd/system/multi-user.target.wants/docker.service
```
文件(root用户 vi打开),找到 ExecStart= 这一行,在这行最后添加加速器地址 --registry-mirror=<加速器地址> ,如:
```
ExecStart=/usr/bin/dockerd --registry-mirror=https://jxus37ad.mi
rror.aliyuncs.com
```
注:对于 1.12 以前的版本, dockerd 换成 docker daemon 。
重新加载配置并且重新启动。
```
sudo systemctl daemon-reload
sudo systemctl restart docker
```
## 检查加速器是否生效
Linux系统下配置完加速器需要检查是否生效,在命令行执行
```
ps -ef | grep dockerd
```
,如果从结果中看到了配置的 ** --registry-mirror** 参数说明配置成
功。
```
sudo ps -ef | grep dockerd
```
root 5346 1 0 19:03 ? 00:00:00 /usr/bin/dockerd
--registry-mirror=https://jxus37ad.mirror.aliyuncs.com