docker安装步骤翻译ubuntu

本问是根据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 使用最新仓库的软件包,:

  1. 使用 sudo or root 权限登陆计算机.
  2. 打开 terminal window(命令窗口).
  3. 更新安装包信息, 确保 APT 使用 https 协议, 同时CA 证书已经被安装.
     $ sudo apt-get update
     $ sudo apt-get install apt-transport-https ca-certificates
    
  4. 添加新的GPGkey.
    $ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    
  5. 用编辑器打开  /etc/apt/sources.list.d/docker.list.

    如果不存在,则新建一个

  6. 删除任何现有输入.
  7. 添加与您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 .

  8. 保存并关闭  /etc/apt/sources.list.d/docker.list file.
  9. 更新APT 软件包索引.
    $ sudo apt-get update
    
  10. 清除旧的repo if it exists.
    $ sudo apt-get purge lxc-docker
    
  11. 确保 APT 是从正确的代码库拉取下来的.
    $ apt-cache policy docker-engine
    

    至此,你可以 使用命令apt-get upgradeAPT 从新代码库拉取代码.

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-* :

  1. 打开主机命令窗口.
  2. 更新包管理器.
    $ sudo apt-get update
    
  3. 安装推荐包.
    $ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
    
  4. 继续安装 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内核并且安装附加包, 通过以下步骤:

  1. 打开主机命令窗口.
  2. 更新包管理器.
    $ sudo apt-get update
    
  3. 安装必需包和可选包
    $ sudo apt-get install linux-image-generic-lts-trusty
    

    根据你的运行环境, 你可能需要根据之前提供表格所描述内容安装其他内容.

  4. 重启主机.
    $ sudo reboot
    
  5. 重启之后, 继续安装Docker.

安装

确保你已经安装过你的Ubuntu版本所需前提要求.

然后, 通过以下步骤安装Docker:

  1. 用具有sudo权限的用户登陆Ubuntu.
  2. Update your APT package index.
    $ sudo apt-get update
    
  3. 安装 Docker.
    $ sudo apt-get install docker-engine
    
  4. 开始使用docker.
    $ sudo service docker start
    
  5. 确认docker已被正确安装.
    $ sudo docker run hello-world
    

    这个命令下载一个测试图片并且在容器(container)中运行. 然后容器container运行, 打印出相关信息.说明安装成功.

可选配置

下面驱动包含一些可选步骤用来配置Ubuntu环境下Docker.

创建 Docker group

docker 进程(daemon)绑定在 Unix套接字(socket), 而不是TCP端口(port). By default that Unix socket is owned by the user root and other users can access it withsudo. For this reason, docker daemon always runs as the root user.

To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

Warning: The docker group is equivalent to the root user; For details on how this impacts security in your system, see Docker Daemon Attack Surface for details.

To create the docker group and add your user:

  1. Log into Ubuntu as a user with sudo privileges.
  2. Create the docker group.
    $ sudo groupadd docker
    
  3. Add your user to docker group.
    $ sudo usermod -aG docker $USER
    
  4. Log out and log back in.

    This ensures your user is running with the correct permissions.

  5. Verify your work by running docker without sudo.
    $ docker run hello-world
    

    If this fails with a message similar to this:

    Cannot connect to the Docker daemon. Is ‘docker daemon‘ running on this host?
    

    Check that the DOCKER_HOST environment variable is not set for your shell. If it is, unset it.

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:

  1. Log into Ubuntu as a user with sudo privileges.
  2. Edit the /etc/default/grub file.
  3. Set the GRUB_CMDLINE_LINUX value as follows:
    GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
    
  4. Save and close the file.
  5. Update GRUB.
    $ sudo update-grub
    
  6. 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:

  1. Log into Ubuntu as a user with sudo privileges.
  2. Verify that UFW is installed and enabled.
    $ sudo ufw status
    
  3. Open the /etc/default/ufw file for editing.
    $ sudo nano /etc/default/ufw
    
  4. Set the DEFAULT_FORWARD_POLICY policy to:
    DEFAULT_FORWARD_POLICY="ACCEPT"
    
  5. Save and close the file.
  6. Reload UFW to use the new setting.
    $ sudo ufw reload
    
  7. 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:

  1. Log into Ubuntu as a user with sudo privileges.
  2. Open the /etc/default/docker file for editing.
    $ sudo nano /etc/default/docker
    
  3. Add a setting for Docker.
    DOCKER_OPTS="--dns 8.8.8.8"
    

    Replace 8.8.8.8 with a local DNS server such as 192.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.

  4. Save and close the file.
  5. 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).

  1. Open the /etc/NetworkManager/NetworkManager.conf file for editing.

    $ sudo nano /etc/NetworkManager/NetworkManager.conf
    
  2. Comment out the dns=dnsmasq line:
    dns=dnsmasq
    
  3. Save and close the file.
  4. Restart both the NetworkManager and 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

Upgrade Docker

To install the latest version of Docker with apt-get:

$ sudo apt-get upgrade docker-engine

卸载

To uninstall the Docker package:

$ sudo apt-get purge docker-engine

To uninstall the Docker package and dependencies that are no longer needed:

$ sudo apt-get autoremove --purge docker-engine

The above commands will not remove images, containers, volumes, or 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.

时间: 2024-10-08 21:10:22

docker安装步骤翻译ubuntu的相关文章

最全的docker 安装步骤

一.安装docker 1. win 10 系统,安装Docker For Windows(Docker Desktop)专业版https://www.cnblogs.com/5bug/p/8506085.html 例如: Windows10下安装Docker的过程,当然这些步骤也是在网上搜索查阅资料得知而来的!具体步骤如下: 一.启用Hyper-V 打开控制面板 - 程序和功能 - 启用或关闭Windows功能,勾选Hyper-V,然后点击确定即可,如图: 点击确定后,启用完毕会提示重启系统,我

docker安装步骤

1.删除就版本的docker输入命令:yum -y remove docker \ docker-common \ docker-selinux \ docker-engine2.使用命令查询docker配置文件包:find / -name docker并逐个删除3.安装开始,首先安装所需的软件包:yum install -y yum-utils device-mapper-persistent-data lvm24.配置软件源,使用下列命令设置 stable 镜像仓库yum-config-ma

docker安装步骤及基于docker容器部署web应用LNMP服务器环境

docker的介绍 docker的定义: 1.docker的三个概念:Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器Docker 镜像 - Docker images: Docker 镜像是 Docker 容器运行时的只读模板Docker 仓库 - Docker registeries: Docker 仓库用来保存镜像,可以理解为代码控制中的代码仓库(Docker Hub)Docker 容器 - Docker containers:每一个 Docke

docker安装及常用命令

一.仓库.镜像.容器 官方docker hub 官方:https://hub.docker.com/explore/ 常用docker 国内镜像源: 网易镜像中心:http://hub-mirror.c.163.com Docker 官方中国区:https://registry.docker-cn.com ustc: https://docker.mirrors.ustc.edu.cn docker国内免费加速器: daocloud:https://www.daocloud.io aliyun:

Ubuntu 16.04安装docker详细步骤

因需要安装opendronemap,而这个依赖于docker,所以记录了一下安装docker的步骤,比较简单.通过apt的docker官方源安装最新的Docker CE(Community Edition),即Docker社区版,是开发人员和小型团队的理想选择. 开始安装 由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本: $ sudo apt-get remove docker docker-engine docker-ce docker.io 更新apt包索引: $

Docker Desktop for Windows 安装步骤

Doker Desktop for Windows 安装要求 Docker Desktop for Windows需要运行Microsoft Hyper-V.如果需要,Docker Desktop for Windows安装程序会为您启用Hyper-V,并重新启动计算机.启用Hyper-V后,VirtualBox(这是不支持Hyper-V的Windows上安装Docker Toolbox时候需要运行的虚拟机软件,这里我们默认你的Windows是支持Hyper-V的)不再起作用,但仍保留任何Vir

ubuntu下docker安装与版本升级

ubuntu 下docker安装与版本升级 一.系统环境 系统:ubuntu-server 14.04 x86_64 内核:3.13.0-32-generic 二.Docker安装 --------------------------------------------------------------------------------- 要想安装最新版本的Docker需要使用Docker源来安装 $ sudo su - root # apt-get -y installapt-transp

Ubuntu下部分软件的简介及其安装步骤

1.安装linux摄像头应用软件cheese sudo apt-get install cheese 2.Ubuntu Tweak    Ubuntu Tweak是一款专门为Ubuntu(GNOME桌面)准备的配置.调整工具.主要面向新手级的普通用户.它可以设置很多并不能在系统首选项中设置的隐藏选项,以满足用户自定义的乐趣.即使是新手,也可以方便地通过它来进行适合自己的系统调整.    安装命令:    第一步:添加tweak源 sudo add-apt-repository ppa:tuala

Ubuntu下fossolgy安装步骤

Ubuntu下fossolgy安装步骤: 需先安装apache2(步骤略) # vi /etc/apt/sources.list deb http://fossology.org/release/2.6.2/Ubuntu/ 12.04  contrib :wq # apt-get update # apt-get install fossolgy 会自动安装apache-php5及postgresql  (记得修改postgres账号密码) 默认安装路径: /etc/fossology./usr