In this, the first chapter, we are going to look at installing and configuring Docker on the following platforms:
macOS Sierra
Windows 10 Professional
Ubuntu 16.04 LTS Desktop
Once installed, we will then look at how you can interact with your local Docker installation.
Before we start our installation, I would like to take a moment to quickly talk about the version of Docker which we will be installing.
At the time of writing, Docker 17.03 has just been released and like most updates, introduces new features as well as changes to existing features. This book has been written with this version of Docker so some of the commands listed may not work or have the same effect when using older versions.
If you already have Docker installed, I would recommend that you check that you are running Docker 17.03 by running the following command:
docker version
If your version of Docker is older that 17.03 then please refer to the upgrade instructions in each of the following sections before proceeding with the rest of the chapters.
As we have already touched upon in the preface, the version of the Docker Engine we are going to be covering in this book is very much a Linux-based tool, so how does it work on macOS and Windows?
It is easy to assume that because macOS is an operating system built on-top of a UNIX like kernel called XNU that Docker will just run as it would do on a Linux machine, unfortunately, a lot of the features which allow Docker to run are not present in the Kernel used by macOS.
While there is the recently launched Windows Subsystem for Linux which is currently in beta, Docker for Windows does not currently take advantage of this, meaning that there is even less of a Linux-like kernel for Docker to use.
Note
The Windows Subsystem for Linux exposes an Ubuntu shell which allows you to run native Linux command-line tools on your Windows installation; for more information, please see https://msdn.microsoft.com/en-gb/commandline/wsl/about.
So how does Docker for Mac and Windows work? The latest versions of macOS and Windows 10 Professional ship with hypervisors which are built into the operating systems kernel, macOS has Hypervisor framework while Windows 10 uses Hyper-V.
Note
Hypervisor framework allows developers to build applications without the need to install third-party kernel extensions, meaning they can leverage full hardware virtualization but remain purely in user space meaning that virtual machines remain sandboxed as if they were running as a native application. The following URL gives a technical overview: https://developer.apple.com/reference/hypervisor
For Docker for Mac Docker have built their own open source framework which works with the Hypervisor framework called HyperKit: you can find out more about HyperKit at https://github.com/docker/HyperKit/.
Hyper-V has been the native hypervisor for Windows-based operating systems since Windows Server 2008; it has also been part of the desktop version of Windows since Windows 8 (Professional and Enterprise editions), it allows users and developers to launch Windows and Linux virtual machines with hardware virtualization in a sandboxed environment. For more information on Hyper-V, please see https://www.microsoft.com/en-us/cloud-platform/server-virtualization.
Docker for Mac and Windows uses these native virtualisation technologies to launch a virtual machine running their MobyLinux distribution, MobyLinux is a light-weight distribution based on Alpine Linux who's only function is to run Docker.
Note
The ISO for Alpine Linux currently weighs in at 26 MB, and a fully functioning minimal installation requires a footprint of ~130MB, while the distribution is extremely small it is as useable and secure as more common Linux distributions. You can find out more at https://alpinelinux.org/.
Docker for Mac and Windows takes care of launching, configuring, and maintaining the virtual machine as well as functions such as networking and mounting filesystems from your local machine to a MobyLinux virtual machine.
Docker for Mac has the following system requirements; if your machine does not meet them then Docker for Mac will fail to install:
Your Mac must be a 2010 or later model, with support for Intel's hardware support for memory man agement unit (MMU) virtualization.
You must be running OS X El Capitan 10.11 or newer. I recommend that you are running the latest macOS.
You must have at least 4GB of RAM.
Versions of VirtualBox 4.3.30 or lower must NOT be installed as this causes problems with Docker for Mac.
To check that your machine can support Docker for Mac you can run the following command:
sysctl kern.hv_support
This should return a 1
when you run the command; this means the virtualization is enabled in your kernel as it is available on your CPU.
Docker for Mac is available from the following URL:
https://store.docker.com/editions/community/docker-ce-desktop-mac
I would recommend sticking with the Stable channel for now as this is the version we will be installing on remote machines in later chapters. Clicking on Get Docker for Mac (stable) will kick off a download of a disk image (DMG) file, once downloaded double-click on the file to mount it.
Like most macOS apps, all you have to do is the following:
Drag the Docker application from the mounted disc image to your applications folder; opening the mounted image in the macOS finder by double clicking on it makes this task easy, as you can see from the following screenshot:
Once the application has been copied, you can close the finder window and open your Applications, find Docker, and open it:
When you open Docker for the first time you will be walked through the initial installation:
Clicking Next will tell you that Docker will ask for your password, it needs this to complete the installation.
After clicking OK and entering your password when prompted a whale icon will appear in the menu bar, and while Docker starts you should see something which looks like the following popup:
Clicking Got it! will close the pop-up. You can tell that Docker has started as the small boxes on the whales back in the icon will stop animating; also left-clicking over the icon will bring up a menu which shows the status of your Docker installation:
Selecting About Docker from the menu will open the following window:
Running the following command in a terminal shows additional information about your Docker installation:
docker version
You should see something like the following output:
As you can see, it gives details on the Docker client which is installed on your macOS host and the MobyLinux virtual machine the client is connecting to.
Docker for Windows has the following system requirements; if your machine does not meet them then Docker for Windows will inform you before exiting:
You must be running a 64bit Windows 10 Pro, Enterprise and Education (1511 November update, build 10586 or later) installation or later (there are plans to support other versions in the future)
Hyper-V must be enabled, though the installer will enable it for you if needed
You must have at least 4GB of RAM
Docker for Windows is available from the following URL:
https://store.docker.com/editions/community/docker-ce-desktop-windows
Like Docker for Mac, I would recommend sticking with the Stable channel. Clicking on Get Docker for Windows (stable) will download an installer; once the installer has finished downloading, you will be given the option to Run it.
When the Docker for Windows installer first opens, you will be greeted by the Docker License Agreement:
Clicking I accept the terms of the License Agreement will enable the Install button, clicking Install with immediately start the installation.
After a minute or two, you should receive confirmation that the installation has been completed.
Making sure that Launch Docker is ticked (it should be by default), click on Finish to open Docker. If you do not have Hyper-V enabled, then you will receive the following prompt:
Clicking Ok will reboot your computer so ensure that you have saved any open documents you may have. Once rebooted, Docker should launch automatically, and like Docker for Mac, you will notice that there is an icon of a whale in your menu bar:
Once Docker has started, selecting About Docker from the menu will open the following window:
Finally, open Windows PowerShell and entering the following command:
docker version
This will return similar information on Docker for Mac, showing both the client information and details on the MobyLinux virtual machine:
There is one more thing with Docker for Windows: you can run native Windows containers. You can enable this feature by selecting the Switch to Windows containers … option from the menu; if it is your first time enabling this feature then you will get the following dialog popup:
Clicking Ok will reboot your machine. Once rebooted, selecting the menu option again will switch you over from using Linux to Windows; this is reflected when you run the following:
docker version
As you can see, the server OS/Arch has changed from linux/amd64 to windows/amd64. We will not be looking at Windows containers in this book; you can change back to Linux containers by using the menu option:
Both Docker for Mac and Windows allow you to easily update your installed version of Docker. If you have an old version of Docker for Mac or Windows installed, you should have been prompted that there is a later version of Docker available when you first open Docker. I you haven't had a prompt then selecting Check for Updates… from the menu will kick off the upgrade process, which is similar to the installation process we have already covered for each of the versions.
If there are no updates, then you will receive a notification confirming you are on the latest version.
If you have been looking at the Docker website, you will notice that there is not a Docker for Linux Desktop download, that is because there is no need for one. Docker is a Linux tool and will run natively on most Linux desktops and servers.
While Docker is available in the main Ubuntu repositories, I would recommend installing Docker using the official repository. You can do this by running the following command:
curl -sSL https://get.docker.com/ | sh
This will configure and install the latest version of Docker Engine. Once installed, you will receive a command to run to give your user permission to run Docker, run the command and then log out.
When you log back in, you will be able to run the following command:
docker version
You should see something like the following:
Note
One thing I haven't mentioned so far is that when we installed Docker for Mac and Windows two additional components were installed. These were Docker Machine and Docker Compose, we will be covering these in Chapter 2, Launching Applications Using Docker and Chapter 3, Docker in the Cloud.
To install Docker Machine run the following commands:
curl -L "https://github.com/docker/machine/releases/download/v0.9.0/docker-machine-$(uname -s)-$(uname -m)" -o / tmp/docker-machine chmod +x /tmp/docker-machine sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
To install Docker Compose, run the following commands:
curl -L "https://github.com/docker/compose/releases/download/1. 10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /tmp/docker-compose sudo cp /tmp/docker-compose /usr/local/bin/docker-compose
Once installed you should be able to run the following two commands:
docker-compose version docker-machine version
Now that we have Docker installed, we are going to quickly test our installation by downloading, running and connecting to a NGINX container.
Note
NGINX is a free, open source, high-performance HTTP server and reverse proxy. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
Tip
A note on Docker commands
Docker 1.13 introduced a slightly altered set of command line instructions for interacting with containers and images. As this syntax will eventually become the new standard we will be using it throughout this book. For more information on the CLI restructure, please see the Docker 1.13 announcement blog post at https://blog.docker.com/2017/01/whats-new-in-docker-1-13/
To download and launch the container all you need to do run the following commands from your terminal prompt;
docker image pull nginx docker container run -d --name nginx-test -p 8080:80 nginx
The first command pulls the NGINX container image from the Docker Hub, and the second command launches our NGINX container, naming it nginx-test
mapping port 8080
on your machine to port 80
on the container.
You can check that the container is running using the following command:
docker container ps
Opening your browser and going to http://localhost:8080/
should show you the default Welcome to NGINX page.
As you can see from the following screens, the process is the same when using Docker for Mac:
Or Docker on Ubuntu 16.04:
As you can see from the screens above, the result of us running the same command on each of the three platforms is exactly the same.
Once you have tested launching a container you can tidy up afterwards by running the following commands to stop and remove the container and then delete the image:
docker container stop nginx-test docker container rm nginx-test docker image rm nginx
In this chapter, we have worked through installing Docker for Mac, Docker for Windows and Docker on Ubuntu 16.04. Hopefully, you will have followed along with one or more of the installations on your local machine. We have also launched our first container and connected to it using our web browser.
In the next chapter, we will go into a lot more detail on the commands we used to launch our test container as well as using Docker Compose to launch multi-container applications.