github.com/rsampaio/docker@v0.7.2-0.20150827203920-fdc73cc3fc31/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, virtualbox, installation,  ubuntu"]
     6  [menu.main]
     7  parent = "smn_linux"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Ubuntu
    12  
    13  Docker is supported on these Ubuntu operating systems:
    14  
    15  - Ubuntu Vivid 15.04
    16  - Ubuntu Trusty 14.04 (LTS)
    17  - Ubuntu Precise 12.04 (LTS)
    18  
    19  This page instructs you to install using Docker-managed release packages and
    20  installation mechanisms. Using these packages ensures you get the latest release
    21  of Docker. If you wish to install using Ubuntu-managed packages, consult your
    22  Ubuntu documentation.
    23  
    24  ## Prerequisites
    25  
    26  Docker requires a 64-bit installation regardless of your Ubuntu version.
    27  Additionally, your kernel must be 3.10 at minimum. The latest 3.10 minor version
    28  or a newer maintained version are also acceptable.
    29  
    30  Kernels older than 3.10 lack some of the features required to run Docker
    31  containers. These older versions are known to have bugs which cause data loss
    32  and frequently panic under certain conditions.
    33  
    34  To check your current kernel version, open a terminal and use `uname -r` to display
    35  your kernel version:
    36  
    37      $ uname -r
    38      3.11.0-15-generic
    39  
    40  >**Caution** Some Ubuntu OS versions **require a version higher than 3.10** to
    41  >run Docker, see the prerequisites on this page that apply to your Ubuntu
    42  >version.
    43  
    44  
    45  ### For Vivid 15.04
    46  
    47  There are no prerequisites for this version.
    48  
    49  ### For Trusty 14.04
    50  
    51  There are no prerequisites for this version.
    52  
    53  ### For Precise 12.04 (LTS)
    54  
    55  For Ubuntu Precise, Docker requires the 3.13 kernel version. If your kernel
    56  version is older than 3.13, you must upgrade it. Refer to this table to see
    57  which packages are required for your environment:
    58  
    59  <style type="text/css"> .tg  {border-collapse:collapse;border-spacing:0;} .tg
    60  td{font-size:14px;padding:10px
    61  5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
    62  .tg-031{width:275px;font-family:monospace} </style> <table class="tg"> <tr> <td
    63  class="tg-031">linux-image-generic-lts-trusty</td> <td class="tg-031e">Generic
    64  Linux kernel image. This kernel has AUFS built in. This is required to run
    65  Docker.</td> </tr> <tr> <td class="tg-031">linux-headers-generic-lts-trusty</td>
    66  <td class="tg-031e">Allows packages such as ZFS and VirtualBox guest additions
    67  which depend on them. If you didn't install the headers for your existing
    68  kernel, then you can skip these headers for the"trusty" kernel. If you're
    69  unsure, you should include this package for safety.</td> </tr> <tr> <td
    70  class="tg-031">xserver-xorg-lts-trusty</td> <td class="tg-031e"
    71  rowspan="2">Optional in non-graphical environments without Unity/Xorg.
    72  <i>Required</i> when running Docker on machine with a graphical environment.
    73  
    74  <p>To learn more about the reasons for these packages, read the installation
    75  instructions for backported kernels, specifically the <a
    76  href="https://wiki.ubuntu.com/Kernel/LTSEnablementStack" target="_blank">LTS
    77  Enablement Stack</a> &mdash; refer to note 5 under each version.</p></td> </tr>
    78  <tr> <td class="tg-031">libgl1-mesa-glx-lts-trusty</td> </tr> </table> &nbsp;
    79  
    80  To upgrade your kernel and install the additional packages, do the following:
    81  
    82  1. Open a terminal on your Ubuntu host.
    83  
    84  2. Update your package manager.
    85  
    86          $ sudo apt-get update
    87  
    88  3. Install both the required and optional packages.
    89  
    90          $ sudo apt-get install linux-image-generic-lts-trusty
    91  
    92      Depending on your environment, you may install more as described in the preceding table.
    93  
    94  4. Reboot your host.
    95  
    96          $ sudo reboot
    97  
    98  5. After your system reboots, go ahead and [install Docker](#installation).
    99  
   100  ## Installation
   101  
   102  Make sure you have installed the prerequisites for your Ubuntu version. Then,
   103  install Docker using the following:
   104  
   105  1. Log into your Ubuntu installation as a user with `sudo` privileges.
   106  
   107  2. Verify that you have `curl` installed.
   108  
   109          $ which curl
   110  
   111      If `curl` isn't installed, install it after updating your manager:
   112  
   113          $ sudo apt-get update
   114          $ sudo apt-get install curl
   115  
   116  3. Get the latest Docker package.
   117  
   118          $ curl -sSL https://get.docker.com/ | sh
   119  
   120      The system prompts you for your `sudo` password. Then, it downloads and
   121      installs Docker and its dependencies.
   122  
   123      >**Note**: If your company is behind a filtering proxy, you may find that the
   124      >`apt-key`
   125      >command fails for the Docker repo during installation. To work around this,
   126      >add the key directly using the following:
   127      >
   128      >       $ curl -sSL https://get.docker.com/gpg | sudo apt-key add -
   129  
   130  4. Verify `docker` is installed correctly.
   131  
   132          $ sudo docker run hello-world
   133  
   134      This command downloads a test image and runs it in a container.
   135  
   136  ## Optional configurations for Docker on Ubuntu 
   137  
   138  This section contains optional procedures for configuring your Ubuntu to work
   139  better with Docker.
   140  
   141  * [Create a docker group](#create-a-docker-group) 
   142  * [Adjust memory and swap accounting](#adjust-memory-and-swap-accounting) 
   143  * [Enable UFW forwarding](#enable-ufw-forwarding) 
   144  * [Configure a DNS server for use by Docker](#configure-a-dns-server-for-docker)
   145  * [Configure Docker to start on boot](#configure-docker-to-start-on-boot)
   146  
   147  ### Create a Docker group		
   148  
   149  The `docker` daemon binds to a Unix socket instead of a TCP port. By default
   150  that Unix socket is owned by the user `root` and other users can access it with
   151  `sudo`. For this reason, `docker` daemon always runs as the `root` user.
   152  
   153  To avoid having to use `sudo` when you use the `docker` command, create a Unix
   154  group called `docker` and add users to it. When the `docker` daemon starts, it
   155  makes the ownership of the Unix socket read/writable by the `docker` group.
   156  
   157  >**Warning**: The `docker` group is equivalent to the `root` user; For details
   158  >on how this impacts security in your system, see [*Docker Daemon Attack
   159  >Surface*](/articles/security/#docker-daemon-attack-surface) for details.
   160  
   161  To create the `docker` group and add your user:
   162  
   163  1. Log into Ubuntu as a user with `sudo` privileges.
   164  
   165      This procedure assumes you log in as the `ubuntu` user.
   166  
   167  3. Create the `docker` group and add your user.
   168  
   169          $ sudo usermod -aG docker ubuntu
   170  
   171  3. Log out and log back in.
   172  
   173      This ensures your user is running with the correct permissions.
   174  
   175  4. Verify your work by running `docker` without `sudo`.
   176  
   177          $ docker run hello-world
   178  
   179  	If this fails with a message similar to this:
   180  
   181  		Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
   182  
   183  	Check that the `DOCKER_HOST` environment variable is not set for your shell.
   184  	If it is, unset it.
   185  
   186  ### Adjust memory and swap accounting
   187  
   188  When users run Docker, they may see these messages when working with an image:
   189  
   190      WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
   191      kernel does not support swap limit capabilities. Limitation discarded.
   192  
   193  To prevent these messages, enable memory and swap accounting on your
   194  system.  Enabling memory and swap accounting does induce both a memory
   195  overhead and a performance degradation even when Docker is not in
   196  use. The memory overhead is about 1% of the total available
   197  memory. The performance degradation is roughly 10%.
   198  
   199  To enable memory and swap on system using GNU GRUB (GNU GRand Unified
   200  Bootloader), do the following:
   201  
   202  1. Log into Ubuntu as a user with `sudo` privileges.
   203  
   204  2. Edit the `/etc/default/grub` file.
   205  
   206  3. Set the `GRUB_CMDLINE_LINUX` value as follows:
   207  
   208          GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
   209  
   210  4. Save and close the file.
   211  
   212  5. Update GRUB.
   213  
   214          $ sudo update-grub
   215  
   216  6. Reboot your system.
   217  
   218  
   219  ### Enable UFW forwarding
   220  
   221  If you use [UFW (Uncomplicated Firewall)](https://help.ubuntu.com/community/UFW)
   222  on the same host as you run Docker, you'll need to do additional configuration.
   223  Docker uses a bridge to manage container networking. By default, UFW drops all
   224  forwarding traffic. As a result, for Docker to run when UFW is
   225  enabled, you must set UFW's forwarding policy appropriately.
   226  
   227  Also, UFW's default set of rules denies all incoming traffic. If you want to be able
   228  to reach your containers from another host then you should also allow incoming
   229  connections on the Docker port (default `2375`).
   230  
   231  To configure UFW and allow incoming connections on the Docker port:
   232  
   233  1. Log into Ubuntu as a user with `sudo` privileges.
   234  
   235  2. Verify that UFW is installed and enabled.
   236  
   237          $ sudo ufw status
   238  
   239  3. Open the `/etc/default/ufw` file for editing.
   240  
   241          $ sudo nano /etc/default/ufw
   242  
   243  4. Set the `DEFAULT_FORWARD_POLICY` policy to:
   244  
   245          DEFAULT_FORWARD_POLICY="ACCEPT"
   246  
   247  5. Save and close the file.
   248  
   249  6. Reload UFW to use the new setting.
   250  
   251          $ sudo ufw reload
   252  
   253  7. Allow incoming connections on the Docker port.
   254  
   255          $ sudo ufw allow 2375/tcp
   256  
   257  ### Configure a DNS server for use by Docker
   258  
   259  Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use
   260  `127.0.0.1` as the default `nameserver` in `/etc/resolv.conf` file. The
   261  NetworkManager also sets up `dnsmasq` to use the real DNS servers of the
   262  connection and sets up `nameserver 127.0.0.1` in /`etc/resolv.conf`.
   263  
   264  When starting containers on desktop machines with these configurations, Docker
   265  users see this warning:
   266  
   267      WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers
   268      can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
   269  
   270  The warning occurs because Docker containers can't use the local DNS nameserver.
   271  Instead, Docker defaults to using an external nameserver.
   272  
   273  To avoid this warning, you can specify a DNS server for use by Docker
   274  containers. Or, you can disable `dnsmasq` in NetworkManager. Though, disabling
   275  `dnsmasq` might make DNS resolution slower on some networks.
   276  
   277  To specify a DNS server for use by Docker:
   278  
   279  1. Log into Ubuntu as a user with `sudo` privileges.
   280  
   281  2. Open the `/etc/default/docker` file for editing.
   282  
   283          $ sudo nano /etc/default/docker
   284  
   285  3. Add a setting for Docker.
   286  
   287          DOCKER_OPTS="--dns 8.8.8.8"
   288  
   289      Replace `8.8.8.8` with a local DNS server such as `192.168.1.1`. You can also
   290      specify multiple DNS servers. Separated them with spaces, for example:
   291  
   292          --dns 8.8.8.8 --dns 192.168.1.1
   293  
   294      >**Warning**: If you're doing this on a laptop which connects to various
   295      >networks, make sure to choose a public DNS server.
   296  
   297  4. Save and close the file.
   298  
   299  5. Restart the Docker daemon.
   300  
   301          $ sudo restart docker
   302  
   303  
   304  &nbsp;
   305  &nbsp;
   306  
   307  **Or, as an alternative to the previous procedure,** disable `dnsmasq` in
   308  NetworkManager (this might slow your network).
   309  
   310  1. Open the `/etc/NetworkManager/NetworkManager.conf` file for editing.
   311  
   312          $ sudo nano /etc/NetworkManager/NetworkManager.conf
   313  
   314  2. Comment out the `dns=dsnmasq` line:
   315  
   316          dns=dnsmasq
   317  
   318  3. Save and close the file.
   319  
   320  4. Restart both the NetworkManager and Docker.
   321  
   322          $ sudo restart network-manager $ sudo restart docker
   323  
   324  ### Configure Docker to start on boot
   325  
   326  Ubuntu uses `systemd` as its boot and service manager `15.04` onwards and `upstart`
   327  for versions `14.10` and below.
   328  
   329  For `15.04` and up, to configure the `docker` daemon to start on boot, run
   330  
   331      $ sudo systemctl enable docker
   332  
   333  &nbsp;
   334  
   335  For `14.10` and below the above installation method automatically configures `upstart`
   336  to start the docker daemon on boot
   337  
   338  ## Upgrade Docker
   339  
   340  To install the latest version of Docker with `curl`:
   341  
   342      $ curl -sSL https://get.docker.com/ | sh
   343  
   344  ## Uninstallation
   345  
   346  To uninstall the Docker package:
   347  
   348      $ sudo apt-get purge docker-engine
   349  
   350  To uninstall the Docker package and dependencies that are no longer needed:
   351  
   352      $ sudo apt-get autoremove --purge docker-engine
   353  
   354  The above commands will not remove images, containers, volumes, or user created
   355  configuration files on your host. If you wish to delete all images, containers,
   356  and volumes run the following command:
   357  
   358      $ rm -rf /var/lib/docker
   359  
   360  You must delete the user created configuration files manually.