2016-04-17 13:42:43 +00:00
|
|
|
|
# Debian操作系统安装Docker
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
## 支持的版本
|
|
|
|
|
|
2016-04-17 13:42:43 +00:00
|
|
|
|
- Debian testing stretch (64-bit)
|
|
|
|
|
- Debian 8.0 Jessie (64-bit)
|
|
|
|
|
- Debian 7.7 Wheezy (64-bit)
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
## 预安装
|
|
|
|
|
|
|
|
|
|
Docker 支持 64 位、内核高于 3.10 的 Debian 操作系统,内核低于 3.10 将导致数据丢失和系统不稳定等问题。
|
2016-04-17 13:42:43 +00:00
|
|
|
|
查看内核版本使用以下命令:
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
2016-04-17 13:42:43 +00:00
|
|
|
|
```
|
|
|
|
|
$ uname -r
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
### 更新APT仓库
|
|
|
|
|
|
|
|
|
|
Docker 的 APT 仓库包含了 1.7.1 及以上版本的 Docker,安装前需要更新 APT 设置,来使用新的仓库:
|
|
|
|
|
|
|
|
|
|
#### 1. 清理旧的仓库信息
|
|
|
|
|
|
2016-04-17 13:42:43 +00:00
|
|
|
|
```sh
|
|
|
|
|
$ apt-get purge lxc-docker*
|
|
|
|
|
$ apt-get purge docker.io*
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
#### 2. 更新和安装软件包
|
|
|
|
|
|
2016-04-17 13:42:43 +00:00
|
|
|
|
```sh
|
|
|
|
|
$ apt-get update
|
|
|
|
|
$ apt-get install apt-transport-https ca-certificates
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
#### 3. 添加 GPG 键
|
|
|
|
|
|
2016-04-17 13:42:43 +00:00
|
|
|
|
```
|
|
|
|
|
$ apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
#### 4. 添加 APT 源
|
|
|
|
|
|
|
|
|
|
编辑文件 `/etc/apt/sources.list.d/docker.list`,清理已存在的信息,写入APT源地址内容。以下以 Debian Jessie 为例,非 Jessie 版本的系统注意修改为自己对应的代号。
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```sh
|
|
|
|
|
$ sudo cat <<EOF > /etc/apt/sources.list.d/docker.list
|
|
|
|
|
deb https://apt.dockerproject.org/repo debian-jessie main
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
其他两个版本内容:
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
|
|
|
|
deb https://apt.dockerproject.org/repo debian-wheezy main
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
deb https://apt.dockerproject.org/repo debian-stretch main
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
#### 5. 校验安装结果
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
|
|
|
|
$ apt-cache policy docker-engine
|
|
|
|
|
docker-engine:
|
|
|
|
|
Installed: 1.11.0-0~jessie
|
|
|
|
|
Candidate: 1.11.0-0~jessie
|
|
|
|
|
Version table:
|
|
|
|
|
*** 1.11.0-0~jessie 0
|
|
|
|
|
500 https://apt.dockerproject.org/repo/ debian-jessie/main amd64 Packages
|
|
|
|
|
100 /var/lib/dpkg/status
|
|
|
|
|
.....
|
|
|
|
|
```
|
|
|
|
|
|
2016-05-25 01:53:45 +00:00
|
|
|
|
以后,当执行 `apt-get upgrade` 等命令时,将使用新设置的的 APT 源。
|
|
|
|
|
|
|
|
|
|
## 安装 Docker
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
|
|
|
|
$ sudo apt-get install docker-engine
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
## 为非 root 用户授权
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
# 如果没有就建立一个 Docker 组
|
2016-04-17 14:01:33 +00:00
|
|
|
|
$ sudo groupadd docker
|
|
|
|
|
|
2016-05-25 01:53:45 +00:00
|
|
|
|
# 增加一个用户(用真实的名字替换下面的 ${USER})到 Docker 组,需重登陆来生效
|
2016-04-17 14:01:33 +00:00
|
|
|
|
$ sudo gpasswd -a ${USER} docker
|
|
|
|
|
|
2016-05-25 01:53:45 +00:00
|
|
|
|
# 重启 Docker 服务
|
2016-04-17 14:01:33 +00:00
|
|
|
|
$ sudo service docker restart
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
## 更新 Docker
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```
|
|
|
|
|
$ apt-get upgrade docker-engine
|
|
|
|
|
```
|
2016-05-25 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
## 卸载 Docker
|
|
|
|
|
|
2016-04-17 14:01:33 +00:00
|
|
|
|
```sh
|
|
|
|
|
# 卸载软件包
|
|
|
|
|
$ sudo apt-get purge docker-engine
|
|
|
|
|
|
|
|
|
|
#卸载依赖包
|
|
|
|
|
$ sudo apt-get autoremove --purge docker-engine
|
|
|
|
|
|
|
|
|
|
#如有必要,执行以下命令,删除全部镜像、容器、数据卷和其他docker相关用户信息:
|
|
|
|
|
$ rm -rf /var/lib/docker
|
|
|
|
|
```
|