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