Installing the Docker Engine
The Docker Engine is built on top of the Linux kernel and it extensively leverages Linux kernel features such as namespaces and cgroups. Due to the burgeoning popularity of Docker, it is now being packaged by all the major Linux distributions so that they can retain their loyal users as well as attract new users. You can install the Docker Engine using the corresponding packaging tool of the Linux distribution, for example, using the apt-get
command for Debian and Ubuntu, and the yum
command for Red Hat, Fedora, and CentOS. Alternatively, you can use the fully automated install script, which will do all the hard work for you behind the scenes.
If you are a Mac or Microsoft Windows user, you can run Docker on Linux emulations (VMs). There are multiple solutions available to run Docker using Linux VM, which is explained in a later subsection. Docker and Microsoft are working towards supporting native Windows containers to run a native Windows application, which is outside the scope of this book.
Note
For all practical purposes, we have chosen the Ubuntu 16.04 LTS (Xenial Xerus) (64-bit) Linux distribution.
Installing Docker on Ubuntu
Docker is currently supported only on 64-bit architecture Linux and the Linux kernel must be 3.10 or later. At the time of writing this book, the latest version of the Docker was 17.03.0-ce. The following steps prescribe the installation procedure of the Docker Engine on Ubuntu Linux 16.04 in detail:
- First, the best practice for installing any software in Ubuntu begins with the resynchronization of the package repository. This step will essentially update the package repository in line with the latest published packages, thus we will ensure that we always get the latest published version using the command shown here:
$ sudo apt-get update
Note
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
- Add the Docker package repository path for Ubuntu 16.04 to your APT sources, as shown here:
$ sudo sh -c "echo deb https://apt.dockerproject.org/repo \ ubuntu-xenial main > /etc/apt/sources.list.d/docker.list"
- Add the GNU Privacy Guard (GPG) key by running the following command:
$ sudo apt-key adv --keyserver \ hkp://p80.pool.sks-keyservers.net:80 --recv-keys \ 58118E89F3A912897C070ADBF76221572C52609D
- Resynchronize with the package repository using the following command:
$ sudo apt-get update
- Install Docker and start the Docker service:
$ sudo apt-get install -y docker-engine
- Having installed the Docker Engine, let's verify our installation by running
docker --version
as shown here:
$ docker --version
Docker version 17.03.0-ce, build 60ccb22
Hurrah!! We have successfully installed Docker version 17.03.0 community edition.
Installing Docker using an automated script
In the previous section, we installed the Docker Engine by manually configuring the GPG key, APT repository, and so on. However, the Docker community has taken a step forward by hiding all these details in an automated install script. This script enables the installation of Docker on most popular Linux distributions, either through the curl
command or through the wget
command, as shown here:
- For the
curl
command:
$ sudo curl -sSL https://get.docker.io/ | sh
- For the
wget
command:
$ sudo wget -qO- https://get.docker.io/ | sh
Note
The preceding automated script approach enforces AUFS as the underlying Docker filesystem because AUFS is preferred over devicemapper
. This script probes the AUFS driver, and then installs it automatically if it is not found in the system. In addition, it also conducts some basic tests upon installation for verifying the sanity.
Installing Docker on the Mac
On a Mac system, you can run Docker on Linux VM. Tools such as Vagrant and Docker Toolbox are quite handy to emulate Linux on Mac and in turn run Docker on it. Docker recently released Docker on Mac as a Beta, using the xhyve
hypervisor to provide the Linux emulation. The xhyve
hypervisor virtualizes the Docker Engine environment and Linux kernel-specific features for the Docker daemon.
Note
It is always recommended that you use Docker for Mac for supported OS X versions 10.10.3, Yosemite or newer.
The following steps describe the installation of Docker for Mac:
- Download Docker for Mac from the link https://download.docker.com/mac/beta/Docker.dmg.
- Double-click to download
Docker.dmg
and move it, as shown here:

- Now, double-click on
Docker.app
inApplications
and it will install all Docker components. During installation, it will ask for the machine's administrative password to install the software. - Upon successful installation, the whale icon will appear in the top status bar:

- Finally, verify the Docker versions:
$ docker --version Docker version 17.03.0-ce, build 60ccb22 $ docker-compose --version docker-compose version 1.11.2, build dfed245 $ docker-machine --version docker-machine version 0.10.0, build 76ed2a6
Installing Docker on Windows
As with the Mac, on Windows, you can also run Docker on Linux VMs using tools such as Vagrant and Docker Toolbox. Recently, Docker released a Beta version of Docker for Windows, which uses Hyper-V to virtualize the Docker Engine and Linux kernel-specific features that are essential to run the Docker Engine.
At the time of writing this book, Docker on Windows is supported only on 64-bit Windows 10 Enterprise and Education (1511 November update, Build 10586 or later). In the future, Docker will support more versions of Windows 10. Be aware that the Hyper-V package must be enabled.
It is always recommended that you use Docker native if you have a supported Windows 10 operating system. The following steps are required to install Docker on Windows:
- Download the Docker for Windows installer from https://download.docker.com/win/beta/InstallDocker.msi.
- Double-click on
InstallDocker.msi
; the installation wizard will start. It will ask for the Windows administrative password to complete the installation:

- Docker starts automatically and the whale will appear in the status bar:

- Finally, verify the Docker versions:
$ docker --version Docker version 17.03.0-ce, build 60ccb22 $ docker-compose --version docker-compose version 1.11.2, build dfed245 $ docker-machine --version docker-machine version 0.10.0, build 76ed2a6
For other versions of Windows, you can install Docker Toolbox from https://docs.docker.com/toolbox/overview/. The Docker Toolbox runs Boot2Docker, a lightweight Linux VM on the Oracle VirtualBox hypervisor and installs the Docker Engine on top of it.