github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/docs/installation/ubuntulinux.md (about)

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