Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Docker

You're reading from   Mastering Docker Unlock new opportunities using Docker's most advanced features

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher
ISBN-13 9781789616606
Length 426 pages
Edition 3rd Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Scott Gallagher Scott Gallagher
Author Profile Icon Scott Gallagher
Scott Gallagher
Russ McKendrick Russ McKendrick
Author Profile Icon Russ McKendrick
Russ McKendrick
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Docker Overview 2. Building Container Images FREE CHAPTER 3. Storing and Distributing Images 4. Managing Containers 5. Docker Compose 6. Windows Containers 7. Docker Machine 8. Docker Swarm 9. Docker and Kubernetes 10. Running Docker in Public Clouds 11. Portainer - A GUI for Docker 12. Docker Security 13. Docker Workflows 14. Next Steps with Docker 15. Assessments 16. Other Books You May Enjoy

Docker installation

Installers are one of the first pieces you need to get up and running with Docker on both your local machine and your server environments. Let's first take a look at which environments you can install Docker in:

  • Linux (various Linux flavors)
  • macOS
  • Windows 10 Professional

In addition, you can run them on public clouds, such as Amazon Web Services, Microsoft Azure, and DigitalOcean, to name a few. With each of the various types of installers listed previously, Docker actually operates in different ways on the operating system. For example, Docker runs natively on Linux, so if you are using Linux, then how Docker runs on your system is pretty straightforward. However, if you are using macOS or Windows 10, then it operates a little differently, since it relies on using Linux.

Let's look at quickly installing Docker on a Linux desktop running Ubuntu 18.04, and then on macOS and Windows 10.

Installing Docker on Linux (Ubuntu 18.04)

As already mentioned, this is the most straightforward installation out of the three systems we will be looking at. To install Docker, simply run the following command from a Terminal session:

$ curl -sSL https://get.docker.com/ | sh
$ sudo systemctl start docker

You will also be asked to add your current user to the Docker group. To do this, run the following command, making sure you replace the username with your own:

$ sudo usermod -aG docker username

These commands will download, install, and configure the latest version of Docker from Docker themselves. At the time of writing, the Linux operating system version installed by the official install script is 18.06.

Running the following command should confirm that Docker is installed and running:

$ docker version

You should see something similar to the following output:

There are two supporting tools that we are going to use in future chapters, which are installed as part of the Docker for macOS or Windows 10 installers.

To ensure that we are ready to use these tools in later chapters, we should install them now. The first tool is Docker Machine. To install this, we first need to get the latest version number. You can find this by visiting the releases section of the project's GitHub page at https://github.com/docker/machine/releases/. At the time of writing, the version was 0.15.0—update the version number in the commands in the following code block with whatever the latest version is when you install it:

$ MACHINEVERSION=0.15.0
$ curl -L https://github.com/docker/machine/releases/download/v$MACHINEVERSION/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine
$ chmod +x /tmp/docker-machine
$ sudo mv /tmp/docker-machine /usr/local/bin/docker-machine

To download and install the next and final tool, Docker Compose, run the following commands, again checking that you are running the latest version by visiting the releases page at https://github.com/docker/compose/releases/:

$ COMPOSEVERSION=1.22.0
$ curl -L https://github.com/docker/compose/releases/download/$COMPOSEVERSION/docker-compose-`uname -s`-`uname -m` >/tmp/docker-compose
$ chmod +x /tmp/docker-compose
$ sudo mv /tmp/docker-compose /usr/local/bin/docker-compose

Once it's installed, you should be able to run the following two commands confirm the versions of the software is correctly:

$ docker-machine version
$ docker-compose version

Installing Docker on macOS

Unlike the command-line Linux installation, Docker for Mac has a graphical installer.

Before downloading, you should make sure that you are running Apple macOS Yosemite 10.10.3 or above. If you are running an older version, all is not lost; you can still run Docker. Refer to the other older operating systems section of this chapter.

You can download the installer from the Docker store, at https://store.docker.com/editions/community/docker-ce-desktop-mac. Just click on the Get Docker link. Once it's downloaded, you should have a DMG file. Double-clicking on it will mount the image, and opening the image mounted on your desktop should present you with something like this:

Once you have dragged the Docker icon to your Applications folder, double-click on it and you will be asked whether you want to open the application you have downloaded. Clicking Yes will open the Docker installer, showing the following:

Click on Next and follow the onscreen instructions. Once it is installed and started, you should see a Docker icon in the top-left icon bar on your screen. Clicking on the icon and selecting About Docker should show you something similar to the following:

You can also open a Terminal window. Run the following command, just as we did in the Linux installation:

$ docker version

You should see something similar to the following Terminal output:

You can also run the following commands to check the versions of Docker Compose and Docker Machine that were installed alongside Docker Engine:

$ docker-compose version
$ docker-machine version

Installing Docker on Windows 10 Professional

Like Docker for Mac, Docker for Windows uses a graphical installer.

Before downloading, you should make sure that you are running Microsoft Windows 10 Professional or Enterprise 64-bit. If you are running an older version or an unsupported edition of Windows 10, you can still run Docker; refer to the other older operating systems section of this chapter for more information.

Docker for Windows has this requirement due to its reliance on Hyper-V. Hyper-V is Windows' native hypervisor and allows you to run x86-64 guests on your Windows machine, be it Windows 10 Professional or Windows Server. It even forms part of the Xbox One operating system.

You can download the Docker for Windows installer from the Docker store at https://store.docker.com/editions/community/docker-ce-desktop-windows/. Just click on the Get Docker button to download the installer. Once it's downloaded, run the MSI package and you will be greeted with the following:

Click on Yes, and then follow the onscreen prompts, which will go through not only installing Docker, but also enabling Hyper-V, if you do not already have it enabled.

Once it's installed, you should see a Docker icon in the icon tray in the bottom right of your screen. Clicking on it and selecting About Docker from the menu will show the following:

Open a PowerShell window and type the following command:

$ docker version

This should also show you similar output to the Mac and Linux versions:

Again, you can also run the following commands to check the versions of Docker Compose and Docker Machine that were installed alongside Docker Engine:

$ docker-compose version
$ docker-machine version

Again, you should see a similar output to the macOS and Linux versions. As you may have started to gather, once the packages are installed, their usage is going to be pretty similar. This will be covered in greater detail later in this chapter.

Older operating systems

If you are not running a sufficiently new operating system on Mac or Windows, then you will need to use Docker Toolbox. Consider the output printed from running the following command:

$ docker version

On all three of the installations we have performed so far, it shows two different versions, a client and server. Predictably, the Linux version shows that the architecture for the client and server are both Linux; however, you may notice that the Mac version shows the client is running on Darwin, which is Apple's Unix-like kernel, and the Windows version shows Windows. Yet both of the servers show the architecture as being Linux, so what gives?

That is because both the Mac and Windows versions of Docker download and run a virtual machine in the background, and this virtual machine runs running a small, lightweight operating system based on Alpine Linux. The virtual machine runs using Docker's own libraries, which connect to the built-in hypervisor for your chosen environment.

For macOS, this is the built-in Hypervisor.framework, and for Windows, Hyper-V.

To ensure that no one misses out on the Docker experience, a version of Docker that does not use these built-in hypervisors is available for older versions of macOS and unsupported Windows versions. These versions utilize VirtualBox as the hypervisor to run the Linux server for your local client to connect to.

VirtualBox is an open source x86 and AMD64/Intel64 virtualization product developed by Oracle. It runs on Windows, Linux, Macintosh, and Solaris hosts, with support for many Linux, Unix, and Windows guest operating systems. For more information on VirtualBox, see https://www.virtualbox.org/.

For more information on Docker Toolbox, see the project's website at https://www.docker.com/products/docker-toolbox/, where you can also download the macOS and Windows installers.

This book assumes that you have installed the latest Docker version on Linux, or have used Docker for Mac or Docker for Windows. While Docker installations using Docker Toolbox should be able to support the commands in this book, you may run into issues around file permissions and ownership when mounting data from your local machine to your containers.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime