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