ubuntulinux.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. :title: Installation on Ubuntu
  2. :description: Please note this project is currently under heavy development. It should not be used in production.
  3. :keywords: Docker, Docker documentation, requirements, virtualbox, vagrant, git, ssh, putty, cygwin, linux
  4. .. _ubuntu_linux:
  5. Ubuntu
  6. ======
  7. .. warning::
  8. These instructions have changed for 0.6. If you are upgrading from
  9. an earlier version, you will need to follow them again.
  10. .. include:: install_header.inc
  11. Docker is supported on the following versions of Ubuntu:
  12. - :ref:`ubuntu_precise`
  13. - :ref:`ubuntu_raring_saucy`
  14. Please read :ref:`ufw`, if you plan to use `UFW (Uncomplicated
  15. Firewall) <https://help.ubuntu.com/community/UFW>`_
  16. .. _ubuntu_precise:
  17. Ubuntu Precise 12.04 (LTS) (64-bit)
  18. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  19. This installation path should work at all times.
  20. Dependencies
  21. ------------
  22. **Linux kernel 3.8**
  23. Due to a bug in LXC, Docker works best on the 3.8 kernel. Precise
  24. comes with a 3.2 kernel, so we need to upgrade it. The kernel you'll
  25. install when following these steps comes with AUFS built in. We also
  26. include the generic headers to enable packages that depend on them,
  27. like ZFS and the VirtualBox guest additions. If you didn't install the
  28. headers for your "precise" kernel, then you can skip these headers for
  29. the "raring" kernel. But it is safer to include them if you're not
  30. sure.
  31. .. code-block:: bash
  32. # install the backported kernel
  33. sudo apt-get update
  34. sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring
  35. # reboot
  36. sudo reboot
  37. Installation
  38. ------------
  39. .. warning::
  40. These instructions have changed for 0.6. If you are upgrading from
  41. an earlier version, you will need to follow them again.
  42. Docker is available as a Debian package, which makes installation
  43. easy. **See the** :ref:`installmirrors` **section below if you are not in
  44. the United States.** Other sources of the Debian packages may be
  45. faster for you to install.
  46. First, check that your APT system can deal with ``https`` URLs:
  47. the file ``/usr/lib/apt/methods/https`` should exist. If it doesn't,
  48. you need to install the package ``apt-transport-https``.
  49. .. code-block:: bash
  50. [ -e /usr/lib/apt/methods/https ] || {
  51. apt-get update
  52. apt-get install apt-transport-https
  53. }
  54. Then, add the Docker repository key to your local keychain.
  55. .. code-block:: bash
  56. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
  57. Add the Docker repository to your apt sources list, update and install the
  58. ``lxc-docker`` package.
  59. *You may receive a warning that the package isn't trusted. Answer yes to
  60. continue installation.*
  61. .. code-block:: bash
  62. sudo sh -c "echo deb https://get.docker.io/ubuntu docker main\
  63. > /etc/apt/sources.list.d/docker.list"
  64. sudo apt-get update
  65. sudo apt-get install lxc-docker
  66. .. note::
  67. There is also a simple ``curl`` script available to help with this process.
  68. .. code-block:: bash
  69. curl -s https://get.docker.io/ubuntu/ | sudo sh
  70. Now verify that the installation has worked by downloading the ``ubuntu`` image
  71. and launching a container.
  72. .. code-block:: bash
  73. sudo docker run -i -t ubuntu /bin/bash
  74. Type ``exit`` to exit
  75. **Done!**, now continue with the :ref:`hello_world` example.
  76. .. _ubuntu_raring_saucy:
  77. Ubuntu Raring 13.04 and Saucy 13.10 (64 bit)
  78. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  79. These instructions cover both Ubuntu Raring 13.04 and Saucy 13.10.
  80. Dependencies
  81. ------------
  82. **Optional AUFS filesystem support**
  83. Ubuntu Raring already comes with the 3.8 kernel, so we don't need to install it. However, not all systems
  84. have AUFS filesystem support enabled. AUFS support is optional as of version 0.7, but it's still available as
  85. a driver and we recommend using it if you can.
  86. To make sure AUFS is installed, run the following commands:
  87. .. code-block:: bash
  88. sudo apt-get update
  89. sudo apt-get install linux-image-extra-`uname -r`
  90. Installation
  91. ------------
  92. Docker is available as a Debian package, which makes installation easy.
  93. .. warning::
  94. Please note that these instructions have changed for 0.6. If you are upgrading from an earlier version, you will need
  95. to follow them again.
  96. First add the Docker repository key to your local keychain.
  97. .. code-block:: bash
  98. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
  99. Add the Docker repository to your apt sources list, update and install the
  100. ``lxc-docker`` package.
  101. .. code-block:: bash
  102. sudo sh -c "echo deb http://get.docker.io/ubuntu docker main\
  103. > /etc/apt/sources.list.d/docker.list"
  104. sudo apt-get update
  105. sudo apt-get install lxc-docker
  106. Now verify that the installation has worked by downloading the ``ubuntu`` image
  107. and launching a container.
  108. .. code-block:: bash
  109. sudo docker run -i -t ubuntu /bin/bash
  110. Type ``exit`` to exit
  111. **Done!**, now continue with the :ref:`hello_world` example.
  112. Giving non-root access
  113. ----------------------
  114. The ``docker`` daemon always runs as the root user, and since Docker version
  115. 0.5.2, the ``docker`` daemon binds to a Unix socket instead of a TCP port. By
  116. default that Unix socket is owned by the user *root*, and so, by default, you
  117. can access it with ``sudo``.
  118. Starting in version 0.5.3, if you (or your Docker installer) create a
  119. Unix group called *docker* and add users to it, then the ``docker``
  120. daemon will make the ownership of the Unix socket read/writable by the
  121. *docker* group when the daemon starts. The ``docker`` daemon must
  122. always run as the root user, but if you run the ``docker`` client as a user in
  123. the *docker* group then you don't need to add ``sudo`` to all the
  124. client commands. As of 0.9.0, you can specify that a group other than ``docker``
  125. should own the Unix socket with the ``-G`` option.
  126. .. warning:: The *docker* group (or the group specified with ``-G``) is
  127. root-equivalent; see :ref:`dockersecurity_daemon` details.
  128. **Example:**
  129. .. code-block:: bash
  130. # Add the docker group if it doesn't already exist.
  131. sudo groupadd docker
  132. # Add the connected user "${USER}" to the docker group.
  133. # Change the user name to match your preferred user.
  134. # You may have to logout and log back in again for
  135. # this to take effect.
  136. sudo gpasswd -a ${USER} docker
  137. # Restart the Docker daemon.
  138. sudo service docker restart
  139. Upgrade
  140. --------
  141. To install the latest version of docker, use the standard ``apt-get`` method:
  142. .. code-block:: bash
  143. # update your sources list
  144. sudo apt-get update
  145. # install the latest
  146. sudo apt-get install lxc-docker
  147. Memory and Swap Accounting
  148. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  149. If you want to enable memory and swap accounting, you must add the following
  150. command-line parameters to your kernel::
  151. cgroup_enable=memory swapaccount=1
  152. On systems using GRUB (which is the default for Ubuntu), you can add those
  153. parameters by editing ``/etc/default/grub`` and extending
  154. ``GRUB_CMDLINE_LINUX``. Look for the following line::
  155. GRUB_CMDLINE_LINUX=""
  156. And replace it by the following one::
  157. GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
  158. Then run ``sudo update-grub``, and reboot.
  159. These parameters will help you get rid of the following warnings::
  160. WARNING: Your kernel does not support cgroup swap limit.
  161. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.
  162. Troubleshooting
  163. ^^^^^^^^^^^^^^^
  164. On Linux Mint, the ``cgroup-lite`` package is not installed by default.
  165. Before Docker will work correctly, you will need to install this via:
  166. .. code-block:: bash
  167. sudo apt-get update && sudo apt-get install cgroup-lite
  168. .. _ufw:
  169. Docker and UFW
  170. ^^^^^^^^^^^^^^
  171. Docker uses a bridge to manage container networking. By default, UFW drops all
  172. `forwarding` traffic. As a result you will need to enable UFW forwarding:
  173. .. code-block:: bash
  174. sudo nano /etc/default/ufw
  175. ----
  176. # Change:
  177. # DEFAULT_FORWARD_POLICY="DROP"
  178. # to
  179. DEFAULT_FORWARD_POLICY="ACCEPT"
  180. Then reload UFW:
  181. .. code-block:: bash
  182. sudo ufw reload
  183. UFW's default set of rules denies all `incoming` traffic. If you want to be
  184. able to reach your containers from another host then you should allow
  185. incoming connections on the Docker port (default 4243):
  186. .. code-block:: bash
  187. sudo ufw allow 4243/tcp
  188. Docker and local DNS server warnings
  189. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  190. Systems which are running Ubuntu or an Ubuntu derivative on the desktop will
  191. use `127.0.0.1` as the default nameserver in `/etc/resolv.conf`. NetworkManager
  192. sets up dnsmasq to use the real DNS servers of the connection and sets up
  193. `nameserver 127.0.0.1` in `/etc/resolv.conf`.
  194. When starting containers on these desktop machines, users will see a warning:
  195. .. code-block:: bash
  196. WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
  197. This warning is shown because the containers can't use the local DNS nameserver
  198. and Docker will default to using an external nameserver.
  199. This can be worked around by specifying a DNS server to be used by the Docker
  200. daemon for the containers:
  201. .. code-block:: bash
  202. sudo nano /etc/default/docker
  203. ---
  204. # Add:
  205. DOCKER_OPTS="--dns 8.8.8.8"
  206. # 8.8.8.8 could be replaced with a local DNS server, such as 192.168.1.1
  207. # multiple DNS servers can be specified: --dns 8.8.8.8 --dns 192.168.1.1
  208. The Docker daemon has to be restarted:
  209. .. code-block:: bash
  210. sudo restart docker
  211. .. warning:: If you're doing this on a laptop which connects to various networks, make sure to choose a public DNS server.
  212. An alternative solution involves disabling dnsmasq in NetworkManager by
  213. following these steps:
  214. .. code-block:: bash
  215. sudo nano /etc/NetworkManager/NetworkManager.conf
  216. ----
  217. # Change:
  218. dns=dnsmasq
  219. # to
  220. #dns=dnsmasq
  221. NetworkManager and Docker need to be restarted afterwards:
  222. .. code-block:: bash
  223. sudo restart network-manager
  224. sudo restart docker
  225. .. warning:: This might make DNS resolution slower on some networks.
  226. .. _installmirrors:
  227. Mirrors
  228. ^^^^^^^
  229. You should ``ping get.docker.io`` and compare the latency to the
  230. following mirrors, and pick whichever one is best for you.
  231. Yandex
  232. ------
  233. `Yandex <http://yandex.ru/>`_ in Russia is mirroring the Docker Debian
  234. packages, updating every 6 hours. Substitute
  235. ``http://mirror.yandex.ru/mirrors/docker/`` for
  236. ``http://get.docker.io/ubuntu`` in the instructions above. For example:
  237. .. code-block:: bash
  238. sudo sh -c "echo deb http://mirror.yandex.ru/mirrors/docker/ docker main\
  239. > /etc/apt/sources.list.d/docker.list"
  240. sudo apt-get update
  241. sudo apt-get install lxc-docker