当前位置:首页 > 技术 > 正文内容

Ubuntu 16.04 部署 Docker CE 完整指南

访客 技术 2026年6月9日 1

环境确认

开始安装前,先确认系统内核及发行版信息:

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 包完成部署:

  1. 访问 官方分发目录,选择对应 Ubuntu 版本及架构(amd64/armhf)
  2. 下载目标版本的 .deb 文件
  3. 执行本地安装:
    admin@xenial-host:~$ sudo dpkg -i /path/to/docker-ce-package.deb
  4. 验证方式与在线安装一致,运行 docker run hello-world 确认服务正常

完成上述步骤后,Docker 引擎已就绪。如需非 root 用户执行容器操作,需将用户加入 docker 组并重新登录会话。

相关文章

Linux crontab 详解

1) crontab 是什么cron 是 Linux 的定时任务守护进程;crontab 是用来编辑/查看“按时间周期执行命令”的表(cron table)。常见两类:用户 crontab:每个用户一份(crontab -e 编辑)系统级 crontab / cron.d:可指定执行用户(/etc/crontab、/etc/cron.d/*)2) crontab 时间...

富文本里可以允许的 HTML 属性

一、所有标签默认允许的安全属性(极少)class        (可选)id           (通常建议禁用)title️ 注意:id 容易被滥用做锚点注入,很多系统直接禁用class 允许的话最好只允许固定前缀(如 editor-*)二、a 标签允许属性<a href="" t...

Mac 安装 Node.js 指南

方法一:通过官网安装包(最简单,适合初学者)如果你只是想快速安装并开始使用,这是最直接的方法。访问 Node.js 官网。页面会显示两个版本:LTS (Recommended For Most Users):长期支持版,最稳定。建议选这个。Current:最新特性版,包含最新功能但可能不够稳定。下载 .pkg 安装包并运行。按照安装向导点击“下一步”即可完成。方法二:使用 Homebrew 安装(...

Dom\HTML_NO_DEFAULT_NS 的副作用:自动加闭合标签

在使用Dom\HTMLDocument时,Dom\HTML_NO_DEFAULT_NS 将禁止在解析过程中设置元素的命名空间, 此设置是为了与DOMDocument向后兼容而存在的。当使用它时,已知的一个副作用就是:自动加闭合标签例如 </img> 为什么会这样?当你使用:Dom\HTML_NO_DEFAULT_NS文档会变成 无命名空间模式,此时内部更接近 XML...

Laravel 事件和监听器创建

在 Laravel 中,使用 Artisan 命令创建 Events(事件) 和 Listeners(监听器) 是非常高效的。你可以通过以下几种方式来实现:1. 手动创建单个 Event如果你只想创建一个事件类,可以使用 make:event 命令:Bashphp artisan make:event UserRegistered执行后,文件将生成在 app/Even...

自定义域名解析神器 dnsmasq

什么是 dnsmasq?dnsmasq 是一个轻量级、功能强大的网络服务工具,专为小型和中等规模网络设计。它是一个综合的网络基础设施解决方案[1]。dnsmasq 能做什么?功能说明应用场景DNS 转发与缓存将 DNS 查询转发到上游服务器(ISP、Google DNS 等),并在本地缓存结果加快 DNS 查询速度,减少外部 DNS 流量本地 DNS解析本地网络设备的主机名,无需编辑&n...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。