github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/installation/linux/ubuntulinux.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = [ "/engine/installation/ubuntulinux/"]
     4  title = "Installation on Ubuntu "
     5  description = "Instructions for installing Docker on Ubuntu. "
     6  keywords = ["Docker, Docker documentation, requirements, apt, installation,  ubuntu"]
     7  [menu.main]
     8  parent = "engine_linux"
     9  weight = -6
    10  +++
    11  <![end-metadata]-->
    12  
    13  # Ubuntu
    14  
    15  Docker is supported on these Ubuntu operating systems:
    16  
    17  - Ubuntu Xenial 16.04 (LTS)
    18  - Ubuntu Wily 15.10
    19  - Ubuntu Trusty 14.04 (LTS)
    20  - Ubuntu Precise 12.04 (LTS)
    21  
    22  This page instructs you to install using Docker-managed release packages and
    23  installation mechanisms. Using these packages ensures you get the latest release
    24  of Docker. If you wish to install using Ubuntu-managed packages, consult your
    25  Ubuntu documentation.
    26  
    27  >**Note**: Ubuntu Utopic 14.10 and 15.04 exist in Docker's `APT` repository but
    28  > are no longer officially supported.
    29  
    30  ## Prerequisites
    31  
    32  Docker requires a 64-bit installation regardless of your Ubuntu version.
    33  Additionally, your kernel must be 3.10 at minimum. The latest 3.10 minor version
    34  or a newer maintained version are also acceptable.
    35  
    36  Kernels older than 3.10 lack some of the features required to run Docker
    37  containers. These older versions are known to have bugs which cause data loss
    38  and frequently panic under certain conditions.
    39  
    40  To check your current kernel version, open a terminal and use `uname -r` to
    41  display your kernel version:
    42  
    43      $ uname -r
    44      3.11.0-15-generic
    45  
    46  >**Note**: If you previously installed Docker using `APT`, make sure you update
    47  your `APT` sources to the new Docker repository.
    48  
    49  ### Update your apt sources
    50  
    51  Docker's `APT` repository contains Docker 1.7.1 and higher. To set `APT` to use
    52  packages from the new repository:
    53  
    54  1. Log into your machine as a user with `sudo` or `root` privileges.
    55  
    56  2. Open a terminal window.
    57  
    58  3. Update package information, ensure that APT works with the `https` method, and that CA certificates are installed.
    59  
    60           $ sudo apt-get update
    61           $ sudo apt-get install apt-transport-https ca-certificates
    62  
    63  4. Add the new `GPG` key.
    64  
    65          $ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    66  
    67  5. Open the `/etc/apt/sources.list.d/docker.list` file in your favorite editor.
    68  
    69      If the file doesn't exist, create it.
    70  
    71  6. Remove any existing entries.
    72  
    73  7. Add an entry for your Ubuntu operating system.
    74  
    75      The possible entries are:
    76  
    77      - On Ubuntu Precise 12.04 (LTS)
    78  
    79              deb https://apt.dockerproject.org/repo ubuntu-precise main
    80  
    81      - On Ubuntu Trusty 14.04 (LTS)
    82  
    83              deb https://apt.dockerproject.org/repo ubuntu-trusty main
    84  
    85      - Ubuntu Wily 15.10
    86  
    87              deb https://apt.dockerproject.org/repo ubuntu-wily main
    88  
    89      - Ubuntu Xenial 16.04 (LTS)
    90  
    91              deb https://apt.dockerproject.org/repo ubuntu-xenial main
    92  
    93      > **Note**: Docker does not provide packages for all architectures. You can find
    94  	> nightly built binaries in https://master.dockerproject.org. To install docker on
    95      > a multi-architecture system, add an `[arch=...]` clause to the entry. Refer to the
    96      > [Debian Multiarch wiki](https://wiki.debian.org/Multiarch/HOWTO#Setting_up_apt_sources)
    97      > for details.
    98  
    99  8. Save and close the `/etc/apt/sources.list.d/docker.list` file.
   100  
   101  9. Update the `APT` package index.
   102  
   103          $ sudo apt-get update
   104  
   105  10. Purge the old repo if it exists.
   106  
   107          $ sudo apt-get purge lxc-docker
   108  
   109  11. Verify that `APT` is pulling from the right repository.
   110  
   111          $ apt-cache policy docker-engine
   112  
   113      From now on when you run `apt-get upgrade`, `APT` pulls from the new repository.
   114  
   115  ### Prerequisites by Ubuntu Version
   116  
   117  - Ubuntu Xenial 16.04 (LTS)
   118  - Ubuntu Wily 15.10
   119  - Ubuntu Trusty 14.04 (LTS)
   120  
   121  For Ubuntu Trusty, Wily, and Xenial, it's recommended to install the
   122  `linux-image-extra` kernel package. The `linux-image-extra` package
   123  allows you use the `aufs` storage driver.
   124  
   125  To install the `linux-image-extra` package for your kernel version:
   126  
   127  1. Open a terminal on your Ubuntu host.
   128  
   129  2. Update your package manager.
   130  
   131          $ sudo apt-get update
   132  
   133  3. Install the recommended package.
   134  
   135          $ sudo apt-get install linux-image-extra-$(uname -r)
   136  
   137  4. Go ahead and install Docker.
   138  
   139  If you are installing on Ubuntu 14.04 or 12.04, `apparmor` is required.  You can install it using: `apt-get install apparmor`
   140  
   141  #### Ubuntu Precise 12.04 (LTS)
   142  
   143  For Ubuntu Precise, Docker requires the 3.13 kernel version. If your kernel
   144  version is older than 3.13, you must upgrade it. Refer to this table to see
   145  which packages are required for your environment:
   146  
   147  <style type="text/css"> .tg  {border-collapse:collapse;border-spacing:0;} .tg
   148  td{font-size:14px;padding:10px
   149  5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
   150  .tg-031{width:275px;font-family:monospace} </style> <table class="tg"> <tr> <td
   151  class="tg-031">linux-image-generic-lts-trusty</td> <td class="tg-031e">Generic
   152  Linux kernel image. This kernel has AUFS built in. This is required to run
   153  Docker.</td> </tr> <tr> <td class="tg-031">linux-headers-generic-lts-trusty</td>
   154  <td class="tg-031e">Allows packages such as ZFS and VirtualBox guest additions
   155  which depend on them. If you didn't install the headers for your existing
   156  kernel, then you can skip these headers for the"trusty" kernel. If you're
   157  unsure, you should include this package for safety.</td> </tr> <tr> <td
   158  class="tg-031">xserver-xorg-lts-trusty</td> <td class="tg-031e"
   159  rowspan="2">Optional in non-graphical environments without Unity/Xorg.
   160  <b>Required</b> when running Docker on machine with a graphical environment.
   161  <br>
   162  <br>To learn more about the reasons for these packages, read the installation
   163  instructions for backported kernels, specifically the <a
   164  href="https://wiki.ubuntu.com/Kernel/LTSEnablementStack" target="_blank">LTS
   165  Enablement Stack</a> &mdash; refer to note 5 under each version.
   166  </td> </tr>
   167  <tr> <td class="tg-031">libgl1-mesa-glx-lts-trusty</td> </tr> </table> &nbsp;
   168  
   169  To upgrade your kernel and install the additional packages, do the following:
   170  
   171  1. Open a terminal on your Ubuntu host.
   172  
   173  2. Update your package manager.
   174  
   175          $ sudo apt-get update
   176  
   177  3. Install both the required and optional packages.
   178  
   179          $ sudo apt-get install linux-image-generic-lts-trusty
   180  
   181      Depending on your environment, you may install more as described in the preceding table.
   182  
   183  4. Reboot your host.
   184  
   185          $ sudo reboot
   186  
   187  5. After your system reboots, go ahead and install Docker.
   188  
   189  ## Install
   190  
   191  Make sure you have installed the prerequisites for your Ubuntu version.
   192  
   193  Then,
   194  install Docker using the following:
   195  
   196  1. Log into your Ubuntu installation as a user with `sudo` privileges.
   197  
   198  2. Update your `APT` package index.
   199  
   200          $ sudo apt-get update
   201  
   202  3. Install Docker.
   203  
   204          $ sudo apt-get install docker-engine
   205  
   206  4. Start the `docker` daemon.
   207  
   208          $ sudo service docker start
   209  
   210  5. Verify `docker` is installed correctly.
   211  
   212          $ sudo docker run hello-world
   213  
   214      This command downloads a test image and runs it in a container. When the
   215      container runs, it prints an informational message. Then, it exits.
   216  
   217  ## Optional configurations
   218  
   219  This section contains optional procedures for configuring your Ubuntu to work
   220  better with Docker.
   221  
   222  * [Create a docker group](#create-a-docker-group)
   223  * [Adjust memory and swap accounting](#adjust-memory-and-swap-accounting)
   224  * [Enable UFW forwarding](#enable-ufw-forwarding)
   225  * [Configure a DNS server for use by Docker](#configure-a-dns-server-for-use-by-docker)
   226  * [Configure Docker to start on boot](#configure-docker-to-start-on-boot)
   227  
   228  ### Create a Docker group		
   229  
   230  The `docker` daemon binds to a Unix socket instead of a TCP port. By default
   231  that Unix socket is owned by the user `root` and other users can access it with
   232  `sudo`. For this reason, `docker` daemon always runs as the `root` user.
   233  
   234  To avoid having to use `sudo` when you use the `docker` command, create a Unix
   235  group called `docker` and add users to it. When the `docker` daemon starts, it
   236  makes the ownership of the Unix socket read/writable by the `docker` group.
   237  
   238  >**Warning**: The `docker` group is equivalent to the `root` user; For details
   239  >on how this impacts security in your system, see [*Docker Daemon Attack
   240  >Surface*](../../security/security.md#docker-daemon-attack-surface) for details.
   241  
   242  To create the `docker` group and add your user:
   243  
   244  1. Log into Ubuntu as a user with `sudo` privileges.
   245  
   246  2. Create the `docker` group.
   247  
   248          $ sudo groupadd docker
   249  
   250  3. Add your user to `docker` group.
   251  
   252          $ sudo usermod -aG docker $USER
   253  
   254  4. Log out and log back in.
   255  
   256      This ensures your user is running with the correct permissions.
   257  
   258  5. Verify your work by running `docker` without `sudo`.
   259  
   260          $ docker run hello-world
   261  
   262  	If this fails with a message similar to this:
   263  
   264  		Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
   265  
   266  	Check that the `DOCKER_HOST` environment variable is not set for your shell.
   267  	If it is, unset it.
   268  
   269  ### Adjust memory and swap accounting
   270  
   271  When users run Docker, they may see these messages when working with an image:
   272  
   273      WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
   274      kernel does not support swap limit capabilities. Limitation discarded.
   275  
   276  To prevent these messages, enable memory and swap accounting on your
   277  system.  Enabling memory and swap accounting does induce both a memory
   278  overhead and a performance degradation even when Docker is not in
   279  use. The memory overhead is about 1% of the total available
   280  memory. The performance degradation is roughly 10%.
   281  
   282  To enable memory and swap on system using GNU GRUB (GNU GRand Unified
   283  Bootloader), do the following:
   284  
   285  1. Log into Ubuntu as a user with `sudo` privileges.
   286  
   287  2. Edit the `/etc/default/grub` file.
   288  
   289  3. Set the `GRUB_CMDLINE_LINUX` value as follows:
   290  
   291          GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
   292  
   293  4. Save and close the file.
   294  
   295  5. Update GRUB.
   296  
   297          $ sudo update-grub
   298  
   299  6. Reboot your system.
   300  
   301  
   302  ### Enable UFW forwarding
   303  
   304  If you use [UFW (Uncomplicated Firewall)](https://help.ubuntu.com/community/UFW)
   305  on the same host as you run Docker, you'll need to do additional configuration.
   306  Docker uses a bridge to manage container networking. By default, UFW drops all
   307  forwarding traffic. As a result, for Docker to run when UFW is
   308  enabled, you must set UFW's forwarding policy appropriately.
   309  
   310  Also, UFW's default set of rules denies all incoming traffic. If you want to
   311  reach your containers from another host allow incoming connections on the Docker
   312  port. The Docker port defaults to `2376` if TLS is enabled or `2375` when it is
   313  not. If TLS is not enabled, communication is unencrypted. By default, Docker
   314  runs without TLS enabled.
   315  
   316  To configure UFW and allow incoming connections on the Docker port:
   317  
   318  1. Log into Ubuntu as a user with `sudo` privileges.
   319  
   320  2. Verify that UFW is installed and enabled.
   321  
   322          $ sudo ufw status
   323  
   324  3. Open the `/etc/default/ufw` file for editing.
   325  
   326          $ sudo nano /etc/default/ufw
   327  
   328  4. Set the `DEFAULT_FORWARD_POLICY` policy to:
   329  
   330          DEFAULT_FORWARD_POLICY="ACCEPT"
   331  
   332  5. Save and close the file.
   333  
   334  6. Reload UFW to use the new setting.
   335  
   336          $ sudo ufw reload
   337  
   338  7. Allow incoming connections on the Docker port.
   339  
   340          $ sudo ufw allow 2375/tcp
   341  
   342  ### Configure a DNS server for use by Docker
   343  
   344  Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use
   345  `127.0.0.1` as the default `nameserver` in `/etc/resolv.conf` file. The
   346  NetworkManager also sets up `dnsmasq` to use the real DNS servers of the
   347  connection and sets up `nameserver 127.0.0.1` in /`etc/resolv.conf`.
   348  
   349  When starting containers on desktop machines with these configurations, Docker
   350  users see this warning:
   351  
   352      WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers
   353      can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
   354  
   355  The warning occurs because Docker containers can't use the local DNS nameserver.
   356  Instead, Docker defaults to using an external nameserver.
   357  
   358  To avoid this warning, you can specify a DNS server for use by Docker
   359  containers. Or, you can disable `dnsmasq` in NetworkManager. Though, disabling
   360  `dnsmasq` might make DNS resolution slower on some networks.
   361  
   362  The instructions below describe how to configure the Docker daemon
   363  running on Ubuntu 14.10 or below. Ubuntu 15.04 and above use `systemd`
   364  as the boot and service manager. Refer to [control and configure Docker
   365  with systemd](../../admin/systemd.md#custom-docker-daemon-options) to
   366  configure a daemon controlled by `systemd`.
   367  
   368  To specify a DNS server for use by Docker:
   369  
   370  1. Log into Ubuntu as a user with `sudo` privileges.
   371  
   372  2. Open the `/etc/default/docker` file for editing.
   373  
   374          $ sudo nano /etc/default/docker
   375  
   376  3. Add a setting for Docker.
   377  
   378          DOCKER_OPTS="--dns 8.8.8.8"
   379  
   380      Replace `8.8.8.8` with a local DNS server such as `192.168.1.1`. You can also
   381      specify multiple DNS servers. Separated them with spaces, for example:
   382  
   383          --dns 8.8.8.8 --dns 192.168.1.1
   384  
   385      >**Warning**: If you're doing this on a laptop which connects to various
   386      >networks, make sure to choose a public DNS server.
   387  
   388  4. Save and close the file.
   389  
   390  5. Restart the Docker daemon.
   391  
   392          $ sudo service docker restart
   393  
   394  
   395  &nbsp;
   396  &nbsp;
   397  
   398  **Or, as an alternative to the previous procedure,** disable `dnsmasq` in
   399  NetworkManager (this might slow your network).
   400  
   401  1. Open the `/etc/NetworkManager/NetworkManager.conf` file for editing.
   402  
   403          $ sudo nano /etc/NetworkManager/NetworkManager.conf
   404  
   405  2. Comment out the `dns=dnsmasq` line:
   406  
   407          dns=dnsmasq
   408  
   409  3. Save and close the file.
   410  
   411  4. Restart both the NetworkManager and Docker.
   412  
   413          $ sudo restart network-manager
   414          $ sudo restart docker
   415  
   416  ### Configure Docker to start on boot
   417  
   418  Ubuntu uses `systemd` as its boot and service manager `15.04` onwards and `upstart`
   419  for versions `14.10` and below.
   420  
   421  For `15.04` and up, to configure the `docker` daemon to start on boot, run
   422  
   423      $ sudo systemctl enable docker
   424  
   425  For `14.10` and below the above installation method automatically configures `upstart`
   426  to start the docker daemon on boot
   427  
   428  ## Upgrade Docker
   429  
   430  To install the latest version of Docker with `apt-get`:
   431  
   432      $ sudo apt-get upgrade docker-engine
   433  
   434  ## Uninstallation
   435  
   436  To uninstall the Docker package:
   437  
   438      $ sudo apt-get purge docker-engine
   439  
   440  To uninstall the Docker package and dependencies that are no longer needed:
   441  
   442      $ sudo apt-get autoremove --purge docker-engine
   443  
   444  The above commands will not remove images, containers, volumes, or user created
   445  configuration files on your host. If you wish to delete all images, containers,
   446  and volumes run the following command:
   447  
   448      $ rm -rf /var/lib/docker
   449  
   450  You must delete the user created configuration files manually.