ubuntu环境下docker安装步骤
本文是根据docker官方文档翻译,原文:https://docs.docker.com/engine/installation/linux/ubuntulinux/
Docker 支持以下 Ubuntu 系统:
- Ubuntu Xenial 16.04 (LTS)
- Ubuntu Wily 15.10
- Ubuntu Trusty 14.04 (LTS)
- Ubuntu Precise 12.04 (LTS)
本页内容指引你安装使用由Docker管理的正式包和管理包. 使用这些安装包能确保你安装 Docker最新发行包. 如果你想安装并使用Ubuntu管理提供的软件包, 参照Ubuntu文档.
备注: Ubuntu Utopic 14.10 和 15.04 依旧在 Docker’s
APT
仓库中,但不再提供官方技术支持.
前提条件
Docker要求是64位Ubuntu(无论哪个版本)。另外,内核必须在最小为3.10。3.10最新版本或更新的版本也行。
3.10之前版本缺少docker运行所需要的特征一些容器。这些老版本的bug,经常导致数据损失。
使用命令: uname -r
来显示内核版本:
$ uname -r
3.11.0-15-generic
备注: 如果你之前安装过Docker 使用的
APT
, 确保升级你的APT
源 到 Docker新版.
更新APT
源
Docker’s APT
仓库 包括 Docker 1.7.1 及更高版本. 为了设定 APT
使用最新仓库的软件包,:
使用
sudo
orroot
权限登陆计算机.打开 terminal window(命令窗口).
更新安装包信息, 确保 APT 使用
https
协议, 同时CA 证书已经被安装.$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
添加新的
GPG
key.$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
用编辑器打开
/etc/apt/sources.list.d/docker.list
.如果不存在,则新建一个
删除任何现有输入.
添加与您Ubuntu操作系统相关条目。
该条目可以是:
On Ubuntu Precise 12.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-precise main
On Ubuntu Trusty 14.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-trusty main
Ubuntu Wily 15.10
deb https://apt.dockerproject.org/repo ubuntu-wily main
Ubuntu Xenial 16.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-xenial main
备注: Docker没有为所有架构提供代码包 .你可以找到 nightly built binaries in https://master.dockerproject.org. To install docker on a multi-architecture system, add an
[arch=...]
clause to the entry. 详细内容参考 Debian Multiarch wiki .保存并关闭
/etc/apt/sources.list.d/docker.list
file.更新
APT
软件包索引.$ sudo apt-get update
清除旧的repo if it exists.
$ sudo apt-get purge lxc-docker
确保
APT
是从正确的代码库拉取下来的.$ apt-cache policy docker-engine
至此,你可以 使用命令
apt-get upgrade
,APT
从新代码库拉取代码.
Ubuntu 版本相关的先决条件
- Ubuntu Xenial 16.04 (LTS)
- Ubuntu Wily 15.10
- Ubuntu Trusty 14.04 (LTS)
针对Ubuntu Trusty, Wily, and Xenial, 推荐安装 the linux-image-extra-*
内核包. linux-image-extra-*
包允许你使用 aufs
存储驱动.
为了安装 linux-image-extra-*
:
打开主机命令窗口.
更新包管理器.
$ sudo apt-get update
安装推荐包.
$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
继续安装 Docker.
Ubuntu Precise 12.04 (LTS)
针对Ubuntu Precise, Docker 要求是 3.13内核. 如果内核版本早于 3.13, 必须更新. 参考如下表格来对比不同包对运行环境的要求:
Package | Description |
---|---|
linux-image-generic-lts-trusty | Generic Linux kernel image. This kernel has AUFS built in. This is required to run Docker. |
linux-headers-generic-lts-trusty | Allows packages such as ZFS and VirtualBox guest additions which depend on them. If you didn't install the headers for your existing kernel, then you can skip these headers for the"trusty" kernel. If you're unsure, you should include this package for safety. |
xserver-xorg-lts-trusty | Optional in non-graphical environments without Unity/Xorg. Required when running Docker on machine with a graphical environment.
To learn more about the reasons for these packages, read the installation instructions for backported kernels, specifically the LTS Enablement Stack — refer to note 5 under each version. |
libgl1-mesa-glx-lts-trusty |
为了更新linux内核并且安装附加包, 通过以下步骤:
打开主机命令窗口.
更新包管理器.
$ sudo apt-get update
安装必需包和可选包
$ sudo apt-get install linux-image-generic-lts-trusty
根据你的运行环境, 你可能需要根据之前提供表格所描述内容安装其他内容.
重启主机.
$ sudo reboot
重启之后, 继续安装Docker.
安装
确保你已经安装过你的Ubuntu版本所需前提要求.
然后, 通过以下步骤安装Docker:
用具有
sudo权限的用户登陆
Ubuntu.Update your
APT
package index.$ sudo apt-get update
安装 Docker.
$ sudo apt-get install docker-engine
开始使用
docker
.$ sudo service docker start
确认
docker
已被正确安装.$ sudo docker run hello-world
这个命令下载一个测试图片并且在容器(container)中运行. 然后容器container运行, 打印出相关信息.说明安装成功.
可选配置
下面驱动包含一些可选步骤用来配置Ubuntu环境下Docker.
- Create a docker group
- Adjust memory and swap accounting
- Enable UFW forwarding
- Configure a DNS server for use by Docker
- Configure Docker to start on boot
创建 Docker group
docker
进程(daemon)绑定在 Unix套接字(socket), 而不是TCP端口(port). 由于Unix默认是 socket权限归root用户所有,其他用户可以通过
sudo访问
. 由此, docker
进程通常使用root
用户运行.
为了避免每次使用docker命令都不得不使用sudo
, 创建名为docker的
Unix group并add users to it. 当docker
daemon 开始,docker
group就会拥有Unix socket 的读写权限(read/writable).
警告: The
docker
group is equivalent to theroot
用户; For details on how this impacts security in your system, 查看Docker Daemon Attack Surface 查看细节.
为了docker
group and添加用户user:
使用具有
sudo
权限得用户登录Ubuntu.创建
docker
group.$ sudo groupadd docker
添加user到
docker
group.$ sudo usermod -aG docker $USER
Log out and log back in.
This ensures your user is running with the correct permissions.
确认不使用
sudo可以运行docker
.$ docker run hello-world
如果提示失败信息与下面相似:
Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
检查
DOCKER_HOST
环境变量 没有设置shell. 如果这样,重置他.
Adjust memory and swap accounting
When users run Docker, they may see these messages when working with an image:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.
To prevent these messages, enable memory and swap accounting on your system. Enabling memory and swap accounting does induce both a memory overhead and a performance degradation even when Docker is not in use. The memory overhead is about 1% of the total available memory. The performance degradation is roughly 10%.
To enable memory and swap on system using GNU GRUB (GNU GRand Unified Bootloader), do the following:
Log into Ubuntu as a user with
sudo
privileges.Edit the
/etc/default/grub
file.Set the
GRUB_CMDLINE_LINUX
value as follows:GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
Save and close the file.
Update GRUB.
$ sudo update-grub
Reboot your system.
Enable UFW forwarding
If you use UFW (Uncomplicated Firewall) on the same host as you run Docker, you’ll need to do additional configuration. Docker uses a bridge to manage container networking. By default, UFW drops all forwarding traffic. As a result, for Docker to run when UFW is enabled, you must set UFW’s forwarding policy appropriately.
Also, UFW’s default set of rules denies all incoming traffic. If you want to reach your containers from another host allow incoming connections on the Docker port. The Docker port defaults to 2376
if TLS is enabled or 2375
when it is not. If TLS is not enabled, communication is unencrypted. By default, Docker runs without TLS enabled.
To configure UFW and allow incoming connections on the Docker port:
Log into Ubuntu as a user with
sudo
privileges.Verify that UFW is installed and enabled.
$ sudo ufw status
Open the
/etc/default/ufw
file for editing.$ sudo nano /etc/default/ufw
Set the
DEFAULT_FORWARD_POLICY
policy to:DEFAULT_FORWARD_POLICY="ACCEPT"
Save and close the file.
Reload UFW to use the new setting.
$ sudo ufw reload
Allow incoming connections on the Docker port.
$ sudo ufw allow 2375/tcp
Configure a DNS server for use by Docker
Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use127.0.0.1
as the default nameserver
in /etc/resolv.conf
file. The NetworkManager also sets up dnsmasq
to use the real DNS servers of the connection and sets up nameserver 127.0.0.1
in /etc/resolv.conf
.
When starting containers on desktop machines with these configurations, Docker users see this warning:
WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers
can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
The warning occurs because Docker containers can’t use the local DNS nameserver. Instead, Docker defaults to using an external nameserver.
To avoid this warning, you can specify a DNS server for use by Docker containers. Or, you can disable dnsmasq
in NetworkManager. Though, disablingdnsmasq
might make DNS resolution slower on some networks.
The instructions below describe how to configure the Docker daemon running on Ubuntu 14.10 or below. Ubuntu 15.04 and above use systemd
as the boot and service manager. Refer to control and configure Docker with systemd to configure a daemon controlled by systemd
.
To specify a DNS server for use by Docker:
Log into Ubuntu as a user with
sudo
privileges.Open the
/etc/default/docker
file for editing.$ sudo nano /etc/default/docker
Add a setting for Docker.
DOCKER_OPTS="--dns 8.8.8.8"
Replace
8.8.8.8
with a local DNS server such as192.168.1.1
. You can also specify multiple DNS servers. Separated them with spaces, for example:--dns 8.8.8.8 --dns 192.168.1.1
Warning: If you’re doing this on a laptop which connects to various networks, make sure to choose a public DNS server.
Save and close the file.
Restart the Docker daemon.
$ sudo service docker restart
Or, as an alternative to the previous procedure, disable dnsmasq
in NetworkManager (this might slow your network).
Open the
/etc/NetworkManager/NetworkManager.conf
file for editing.$ sudo nano /etc/NetworkManager/NetworkManager.conf
Comment out the
dns=dnsmasq
line:dns=dnsmasq
保存并关闭.
重启NetworkManager 和 Docker.
$ sudo restart network-manager
$ sudo restart docker
Configure Docker to start on boot
Ubuntu uses systemd
as its boot and service manager 15.04
onwards andupstart
for versions 14.10
and below.
For 15.04
and up, to configure the docker
daemon to start on boot, run
$ sudo systemctl enable docker
For 14.10
and below the above installation method automatically configuresupstart
to start the docker daemon on boot
更新Docker
使用apt-get来安装Docker最新版:
$ sudo apt-get upgrade docker-engine
卸载
卸载Docker包:
$ sudo apt-get purge docker-engine
卸载Docker包及依赖:
$ sudo apt-get autoremove --purge docker-engine
上面命令会删除images, containers, volumes, user created configuration files on your host. If you wish to delete all images, containers, and volumes run the following command:
$ rm -rf /var/lib/docker
You must delete the user created configuration files manually.
ubuntu环境下docker安装步骤的更多相关文章
- Docker版本与centos和ubuntu环境下docker安装介绍
# Docker版本与安装介绍 * Docker-CE 和 Docker-EE * Centos 上安装 Docker-CE * Ubuntu 上安装 Docker-CE ## Docker-CE和D ...
- Ubuntu环境下Anaconda安装TensorFlow并配置Jupyter远程访问
本文主要讲解在Ubuntu系统中,如何在Anaconda下安装TensorFlow以及配置Jupyter Notebook远程访问的过程. 在官方文档中提到,TensorFlow的安装主要有以下五种形 ...
- Docker基础:VMware虚拟机Centos7环境下docker安装及使用
1.docker简介 2.docker安装 3.卸载docker 4.阿里云镜像加速 5.docker的常用命令 5.1 帮助命令 5.2 镜像命令 5.3 容器命令 5.4 后台启动命令 5.5 查 ...
- ubuntu环境下docker的安装与操作
只要按照本文的步骤一步步的走,就能正确的安装docker并使用,ubuntu需要联网 1. 在Ubuntu中安装Docker 更新ubuntu的apt源索引 sudo apt-get update 安 ...
- CentOS && Ubuntu 环境下 Docker 的安装配置
CentOS 7 install Docker Docker 支持的 centos 版本:CentOS 6.5(64-bit)或更高的版本 使用 yum 安装 1)确保 yum 包更新到最新 [roo ...
- ubuntu环境下jdk安装及jenkins安装
本文内容参考http://jingyan.baidu.com/article/c33e3f48a3365dea15cbb5c9.html 1 jdk下载 安装 http://www.oracle.co ...
- 强化学习 平台 openAI 的 gym 安装 (Ubuntu环境下如何安装Python的gym模块)
openAI 公司给出了一个集成较多环境的强化学习平台 gym , 本篇博客主要是讲它怎么安装. openAI公司的主页: https://www.openai.com/systems/ 从主页上我 ...
- Ubuntu环境下SSH的安装及使用
Ubuntu环境下SSH的安装及使用 SSH是指Secure Shell,是一种安全的传输协议,Ubuntu客户端可以通过SSH访问远程服务器 .SSH的简介和工作机制可参看上篇文章SSH简介及工作机 ...
- Ubuntu环境下非root用户指定版本Python的安装及虚拟环境virtualenv的使用
Ubuntu环境下非root用户指定版本Python的安装及虚拟环境virtualenv的使用 参考博客: https://blog.csdn.net/leviopku/article/details ...
随机推荐
- Linux 编译安装 源代码
编译安装 源代码包的安装一般为下载软件源代码,然后编译安装. 常见的C程序软件的安装步骤是 configure, make, make install三部曲,大致是下面这样操作: 首先得安装gcc.m ...
- JavaEE XML XSL转换(XSLT)
XSL转换(XSLT) @author ixenos 定义: XSL转换机制可以指定将XML文档转换为其他格式的规则,例如,txt纯文本.XHTML或其他任何XML格式. 用途: XSLT通常用来将某 ...
- Shell终端收听音乐--网易云音乐命令行版
Musicbox:网易云音乐命令行版本 高品质网易云音乐命令行版本,简洁优雅,丝般顺滑,基于Python编写. 这款命令行的客户端使用 Python 构建,以 mpg123 作为播放后端: Vim 式 ...
- UGUI和现实世界的比例关系
之前测试过默认大小的 Cube 在现实中的 比例关系,得出基本单位为 m 的结论,至于 UGUI和现实世界的比例关系 看下图就知道了: Cube Collider 的大小: Button 的大小: 其 ...
- Centos 7 系统安装完毕修改网卡名为eth0
从CentOS/RHEL7起,可预见的命名规则变成了默认.这一规则,接口名称被自动基于固件,拓扑结构和位置信息来确定.现在,即使添加或移除网络设备,接口名称仍然保持固定,而无需重新枚举,和坏掉的硬件可 ...
- ES 6 : 字符串的扩展
1. 字符的Unicode表示法 JavaScript允许表示\u0000—\uFFFF之间的字符.超出这个范围,必须用2个双字节的形式表达.如:"\u20BB7"是汉字 &quo ...
- Qt 外观之一 ——Qt Style Sheet
Qt Style Sheet 目录 使用 对于应用程序 创建自定义控件 QSS语法 一般选择器(selector) 伪选择器 解决冲突 使用specificity Namespace冲突 级联效应 设 ...
- myeclipse里如何添加mysql数据库
首先声明,这只是我本人的一些经验,不代表任何集体和个人的利益,请勿没事就当喷子来喷我.我希望对一些对这方面学习的朋友有帮助,当然,我自己也是菜鸟级别啦!!!!!!!!!!!! 首先是电脑必要安装了my ...
- ASP.NET Calendar(日历控件)
定义和用法 Calendar 控件用于在浏览器中显示日历. 该控件可显示某个月的日历,允许用户选择日期,也可以跳到前一个或下一个月. 属性 属性 描述 .NET Caption 日历的标题. 2.0 ...
- 找轮转后的有序数组中第K小的数
我们可以通过二分查找法,在log(n)的时间内找到最小数的在数组中的位置,然后通过偏移来快速定位任意第K个数. 此处假设数组中没有相同的数,原排列顺序是递增排列. 在轮转后的有序数组中查找最小数的算法 ...