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