Ubuntu 安装docker,ubuntu安装docker


官方原文:https://docs.docker.com/engine/installation/linux/ubuntulinux/

Ubuntu

Docker is supported on these Ubuntu operating systems:

  • Ubuntu Xenial 16.04 (LTS)
  • Ubuntu Wily 15.10
  • Ubuntu Trusty 14.04 (LTS)
  • Ubuntu Precise 12.04 (LTS)

This page instructs you to install using Docker-managed release packages and installation mechanisms. Using these packages ensures you get the latest release of Docker. If you wish to install using Ubuntu-managed packages, consult your Ubuntu documentation.

Note: Ubuntu Utopic 14.10 and 15.04 exist in Docker’s APTrepository but are no longer officially supported.

Prerequisites

Docker requires a 64-bit installation regardless of your Ubuntu version. Additionally, your kernel must be 3.10 at minimum. The latest 3.10 minor version or a newer maintained version are also acceptable.

Kernels older than 3.10 lack some of the features required to run Docker containers. These older versions are known to have bugs which cause data loss and frequently panic under certain conditions.

To check your current kernel version, open a terminal and useuname -r to display your kernel version:

$ uname -r
3.11.0-15-generic

Note: If you previously installed Docker using APT, make sure you update your APT sources to the new Docker repository.

Update your apt sources

Docker’s APT repository contains Docker 1.7.1 and higher. To setAPT to use packages from the new repository:

Prerequisites by Ubuntu Version

  • Ubuntu Xenial 16.04 (LTS)
  • Ubuntu Wily 15.10
  • Ubuntu Trusty 14.04 (LTS)

For Ubuntu Trusty, Wily, and Xenial, it’s recommended to install thelinux-image-extra kernel package. The linux-image-extrapackage allows you use the aufs storage driver.

To install the linux-image-extra package for your kernel version:

If you are installing on Ubuntu 14.04 or 12.04, apparmor is required. You can install it using: apt-get install apparmor

Ubuntu Precise 12.04 (LTS)

For Ubuntu Precise, Docker requires the 3.13 kernel version. If your kernel version is older than 3.13, you must upgrade it. Refer to this table to see which packages are required for your environment:

 

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

 

 

To upgrade your kernel and install the additional packages, do the following:

Install

Make sure you have installed the prerequisites for your Ubuntu version.

Then, install Docker using the following:

Optional configurations

This section contains optional procedures for configuring your Ubuntu to work better with 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

Create a Docker group

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. 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 thedocker 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, seeDocker Daemon Attack Surface for details.

To create the docker group and add your user:

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:

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:

Configure a DNS server for use by Docker

Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use 127.0.0.1 as the default nameserver in/etc/resolv.conf file. The NetworkManager also sets updnsmasq to use the real DNS servers of the connection and sets upnameserver 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, disabling dnsmasq 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 usesystemd as the boot and service manager. Refer to control and configure Docker with systemd to configure a daemon controlled bysystemd.

To specify a DNS server for use by Docker:

   

Or, as an alternative to the previous procedure, disablednsmasq in NetworkManager (this might slow your network).

Configure Docker to start on boot

Ubuntu uses systemd as its boot and service manager 15.04onwards and upstart 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 configures upstart 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

Uninstallation

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.

相关内容

    暂无相关文章