Ubuntu 16.04 部署 Docker CE 完整指南
环境确认
开始安装前,先确认系统内核及发行版信息:
admin@xenial-host:~$ uname -r
4.8.0-36-generic
admin@xenial-host:~$ lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial安装前置依赖
配置 apt 以支持 HTTPS 源,并安装必要的工具链:
admin@xenial-host:~$ sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common导入 Docker 官方签名密钥
获取并校验 GPG 公钥,确保软件包来源可信:
admin@xenial-host:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
admin@xenial-host:~$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22配置稳定版软件源
根据当前系统代号添加 Docker 官方仓库:
admin@xenial-host:~$ CODENAME=$(lsb_release -cs)
admin@xenial-host:~$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
${CODENAME} \
stable"更新索引并安装
同步软件包列表后,执行 Docker CE 的安装:
admin@xenial-host:~$ sudo apt-get update
命中:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
获取:2 https://download.docker.com/linux/ubuntu xenial InRelease [20.1 kB]
获取:3 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages [1,479 B]
已下载 21.6 kB,耗时 18秒
admin@xenial-host:~$ sudo apt-get install -y docker-ce代理配置(可选)
若处于需代理访问外网的环境,按以下方式配置 systemd 服务:
admin@xenial-host:~$ sudo mkdir -p /etc/systemd/system/docker.service.d/
admin@xenial-host:~$ sudo tee /etc/systemd/system/docker.service.d/proxy.conf > /dev/null <<'EOF'
[Service]
Environment="HTTP_PROXY=http://10.144.1.10:8080"
Environment="HTTPS_PROXY=https://10.144.1.10:8080"
Environment="NO_PROXY=localhost,127.0.0.1,.local"
EOF
admin@xenial-host:~$ sudo systemctl daemon-reload
admin@xenial-host:~$ sudo systemctl restart docker
admin@xenial-host:~$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://10.144.1.10:8080 HTTPS_PROXY=https://10.144.1.10:8080 NO_PROXY=localhost,127.0.0.1,.local验证安装结果
检查服务端与客户端版本信息,并运行测试镜像:
admin@xenial-host:~$ docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:14:09 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:14:09 2017
OS/Arch: linux/amd64
Experimental: false
admin@xenial-host:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.设置开机自启
将 Docker 服务加入系统启动项,避免重启后手动启动:
admin@xenial-host:~$ sudo systemctl enable docker离线安装方式
当无法连接官方仓库时,可通过手动下载 deb 包完成部署:
- 访问 官方分发目录,选择对应 Ubuntu 版本及架构(amd64/armhf)
- 下载目标版本的
.deb文件 - 执行本地安装:
admin@xenial-host:~$ sudo dpkg -i /path/to/docker-ce-package.deb - 验证方式与在线安装一致,运行
docker run hello-world确认服务正常
完成上述步骤后,Docker 引擎已就绪。如需非 root 用户执行容器操作,需将用户加入 docker 组并重新登录会话。