一、环境准备
Docker CE 支持以下版本的 Ubuntu 操作系统:
- Artful 17.10 (Docker CE 17.11 Edge +)
- Xenial 16.04 (LTS)
- Trusty 14.04 (LTS)
Docker CE 可以安装在 64 位的 x86 平台或 ARM 平台上。 Ubuntu 发行版中,LTS(Long-Term-Support)
长期支持版本,会获得 5 年的升级维护支持,这样的版本会更稳定,因此在生产环境中推荐使用 LTS 版本,本次安装的环境为 Ubuntu 16.04
。
二、安装步骤
2.1 使用 APT 方式安装
卸载旧版本:
1 2 3 |
sudo apt-get remove docker \ docker-engine \ docker.io |
添加 CA 证书:
1 2 3 4 5 6 7 |
sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common |
添加 GPG 证书:
1 2 3 4 |
# 使用国内源 curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # 官方源 # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
添加软件源到 source.list
:
1 2 3 4 5 6 7 8 9 10 11 12 |
# 国内源 sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable" # 官方源 # sudo add-apt-repository \ # "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ # $(lsb_release -cs) \ # stable" |
更新软件包缓存并安装 docker:
1 2 |
sudo apt-get update sudo apt-get install docker-ce |
2.2 使用脚本安装
在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,Ubuntu 系统上可以使用这套脚本安装:
1 2 |
curl -fsSL get.docker.com -o get-docker.sh sudo sh get-docker.sh --mirror Aliyun |
三、优化工作
3.1 建立 docker 组
默认情况下,docker 命令会使用 Unix socket 和 Docker 通讯,而系统中只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket,所以有必要把当前用户添加到 docker 组中:
1 2 |
sudo groupadd docker # 使用 apt 方式安装的默认已经创建了 docker 组 sudo usermod -aG docker $USER |
3.2 镜像加速器
官方加速器:把下面的内容复制到/etc/docker/daemon.json
文件即可。
1 2 3 |
{ "registry-mirrors": ["https://registry.docker-cn.com"] } |
阿里云加速器:开通后会有和上面类似加速地址以及配置方法,也是复制到/etc/docker/daemon.json
。
校验是否安装成功:
1 2 3 4 |
> docker info # 包含以下信息表示设置成功 Registry Mirrors: https://******.mirror.aliyuncs.com/ |
四、启动 docker
1 2 3 4 5 6 7 8 |
# 启动 docker sudo systemctl start docker # 关闭 docker sudo systemctl stop docker # 添加到开机启动 sudo systemctl enable docker |
启动 docker:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
> docker run hello-world # 出现以下信息表示成功 Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ |
评论