Troubleshooting Docker
上QQ阅读APP看书,第一时间看更新

Installing Docker on Ubuntu

Let's get started with installing Docker on Ubuntu 14.04 LTS 64-bit. We can use AWS AMI in order to create our setup. The image can be launched on AMI directly with the help of following link:

http://thecloudmarket.com/image/ami-a21529cc--ubuntu-images-hvm-ssd-ubuntu-trusty-14-04-amd64-server-20160114-5

The following diagram illustrates the installation steps required to install Docker on Ubuntu 14.04 LTS:

Prerequisites

Docker requires a 64-bit installation, regardless of the Ubuntu version. The kernel must be 3.10 at minimum.

Let's check our kernel version, using the following command:

$ uname -r

The output is a kernel version of 3.13.x, which is fine:

3.13.0-74-generic

Updating package information

Perform the following steps to update the APT repository and have necessary certificates installed:

  1. Docker's APT repository contains Docker 1.7.x or higher. To set APT to use packages from the new repository:
     $ sudo apt-get update 
    
  2. Run the following command to ensure that APT works with the HTTPS method and CA certificates are installed:
     $ sudo apt-get install apt-transport-https ca-certificates 
    

The apt-transport-https package enables us to use deb https://foo distro main lines in the /etc/apt/sources.list so that package managers, which use the libapt-pkg library, can access metadata and packages available in sources accessible over HTTPS.

The ca-certificates are container's PEM files of CA certificates, which allow SSL-based applications to check for the authenticity of SSL connections.

Adding a new GPG key

GNU Privacy Guard (known as GPG or GnuPG) is a free encryption software that's compliant with the OpenPGP (RFC4880) standard:

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D 

The output will be similar to the following listing:

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.SaGDv5OvNN --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D gpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.net gpg: key 2C52609D: public key "Docker Release Tool (releasedocker) <docker@docker.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)

Troubleshooting

If you find the sks-keyservers to be unavailable, you can try the following command:

$ sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D 

Adding a new package source for Docker

The Docker repository can be added in the following way to the APT repository:

  1. Update /etc/apt/sources.list.d with a new source as Docker repository.
  2. Open the /etc/apt/sources.list.d/docker.list file and update it with the following entry:
     deb https://apt.dockerproject.org/repo ubuntu-trusty main
    

Updating Ubuntu packages

The Ubuntu packages after adding Docker repository can be updated, as shown here:

$ sudo apt-get update

Install linux-image-extra

For Ubuntu Trusty, it's recommended to install the linux-image-extra kernel package; the linux-image-extra package allows the AUFS storage driver to be used:

$ sudo apt-get install linux-image-extra-$(uname -r) 

The output will be similar to the following listing:

Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: crda iw libnl-3-200 libnl-genl-3-200 wireless-regdb The following NEW packages will be installed: crda iw libnl-3-200 libnl-genl-3-200 linux-image-extra-3.13.0-74-generic wireless-regdb 0 upgraded, 6 newly installed, 0 to remove and 70 not upgraded. Need to get 36.9 MB of archives. After this operation, 152 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ trusty/main libnl-3-200 amd64 3.2.21-1 [44 .. Updating /boot/grub/menu.lst ... done run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.13.0-74-generic /boot/vmlinuz-3.13.0-74-generic Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.13.0-74-generic Found initrd image: /boot/initrd.img-3.13.0-74-generic done Processing triggers for libc-bin (2.19-0ubuntu6.6) ...

Optional - installing AppArmor

If it is not already installed, install AppArmor using the following command:

$ apt-get install apparmor

The output will be similar to the following listing:

sudo: unable to resolve host ip-172-30-0-227 Reading package lists... Done Building dependency tree Reading state information... Done apparmor is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 70 not upgraded.

Docker installation

Let's get started with installing Docker Engine on Ubuntu using the official APT package:

  1. Update APT package index:
     $ sudo apt-get update
    
  2. Install Docker Engine:
     $ sudo apt-get install docker-engine 
    
  3. Start the Docker daemon:
     $ sudo service docker start 
    
  4. Verify that Docker is installed correctly:
     $ sudo docker run hello-world 
    
  5. This is how the output would look like:
     Latest: Pulling from library/hello-world 03f4658f8b78: Pull complete a3ed95caeb02: Pull complete Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8b c72074cc1ca36966a7 Status: Downloaded newer image for hello-world:latest Hello from Docker. This message shows that your installation appears to be working correctly.