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