Getting started with Docker: Installation, first steps

; Date: Thu Oct 08 2020

Tags: Docker »»»» Docker MAMP

Let's start this journey into Docker by learning how to install it on popular systems, namely macOS, Windows and Linux. Installation is very simple thanks to the hard work of the Docker team. You youngsters don't know how easy you have it now that Docker for Mac and Docker for Windows exist. Long gone are the days when we had to install VirtualBox along with a specialized virtual machine to use Docker.

Docker is an ecosystem of tools, most of which are open source. This includes tools for constructing Docker images, running Docker containers, interacting with remote Docker servers, and orchestrating Docker deployments over multiple machines using either Docker Swarm or Kubernetes.

Learning about all that starts with installing Docker CE on your laptop. The official instructions are available on the website. What follows is our attempt to explain it better than did the Docker team.

On Linux systems, Docker runs natively using normal Linux background processes that are managed by systems like systemctl. Docker containers are a lightweight virtualized Linux execution environment. This is not a virtual machine tool like VirtualBox or KVM, but a light weight container environment. For example processes inside the running Docker container are actually processes running on the host operating system, with Docker creating multiple layers of redirection around each process. The result is that one container might be built with Debian, another built with Arch Linux, another built with Gentoo, but the host operating system is Linux Mint, with Docker keeping everything straight.

On both macOS and Windows, however, the host operating system is not Linux, obviously, and Docker does not run natively. Instead, the Docker for Windows and Docker for macOS applications contain a lightweight virtual Linux environment within which is a Docker execution environment. Inside that virtual Linux machine is the same Docker we'd run natively on Linux, just hidden within a Linux VM. The good news is that, unlike the olden days a few years ago where we had to build that Linux VM ourselves, the Docker team has made sure the Docker application takes care of everything for us. You'll find that Docker is very lightweight and can be left running in the background of your laptop with no impact on system performance.

In this article we'll first discuss installing Docker Desktop for macOS and Windows, then installing Docker Community Edition for Linux, and wrap up with a quick introduction to using Docker command-line tools.

Installing Docker on macOS

Official instructions: (docs.docker.com) https://docs.docker.com/docker-for-mac/install/

Pre-requisites:

  • The Mac hardware must be a 2010 or later model, with Intel’s hardware support for memory management unit (MMU) virtualization, including Extended Page Tables (EPT) and Unrestricted Mode. The command sysctl kern.hv_support detects whether the computer has the required support.
  • The macOS version must be at least 10.14, a.k.a. Mojave or Catalina. It will run on macOS 10.13 but you will be constantly nagged to upgrade.
  • VirtualBox prior to version 4.3.30 must not be installed.

Installation couldn't be simpler - you download the Docker for Mac bundle, which is named Docker.dmg. As the name implies this is a macOS disk image, which you double-click to open. Once opened, you drag the Docker icon to the Applications folder just like zillions of other macOS applications.

The Docker application icon on macOS. For Windows, you'll find Docker on the Start menu.

Once copied to the Applications folder, you double click the Docker icon to launch the application.

It starts like a regular Mac application, and in all ways behaves like one. The first time it's launched you'll be taken through a setup process.

An icon is added to the top status bar. The icon shows current status, and gives access to a menu showing further details.

Docker for Mac relies on an extremely light-weight hypervisor, HyperKit. Inside that hypervisor is running a Linux system with enough capability to host Docker services. Processes associated with your Docker containers are not running in macOS, but instead are running in this Linux image inside the hypervisor.

Installing Docker on Windows

Official instructions: (docs.docker.com) https://docs.docker.com/docker-for-windows/install/

Pre-requisites:

  • Windows 10, 64-bit, either Pro, Enterprise or Education versions
  • The Hyper-V and Containers features of Windows must be enabled
  • The CPU must support 64-bit execution and have Second Level Address Translation (SLAT)
  • BIOS-level hardware virtualization must be enabled

Once you've downloaded the installer, Docker for Windows Installer.exe, run it to go through the install wizard.

Once Docker is installed, it is launched through the Start menu, just like any Windows application. From here it behaves like a Windows app, for example an icon is added to the taskbar.

Docker for Windows relies on an extremely light-weight hypervisor, Hyper-V. This is an optional feature of Windows 10 Pro/Enterprise/etc that can be enabled. Like for Docker for Mac, the Docker containers you run on Windows will not be Windows processes, but instead will run in the Linux image running inside the Hyper-V hypervisor.

The Docker Desktop GUI

Both the Windows and macOS Docker installations come with a GUI application with which we can manage Docker. This application is started either from the application icon, or the taskbar menu.

The Docker desktop GUI.

If there were any Docker containers executing they'd be listed here. But, as we can see there are none, and instead there's a helpful suggestion for getting started. We'll get to this later on.

Notice a "gear" icon at the top. This gets you into the Preferences pane. For example we can control whether Docker automatically starts when the computer boots, and other settings.

Settings for Docker advanced features.

Enabling the experimental features does what it sounds like, which is to keep our Docker environment updated with the latest features. As of this writing these features include closer integration with AWS that we will use later in the book.

Before heading to the Docker command-line let's talk about installation on Linux.

Linux installation

Unlike with Windows or macOS, on Linux we install several components separately. This starts with installing Docker Engine, or the component that handles Docker execution and some of the command line tools.

The documentation root is at: (docs.docker.com) https://docs.docker.com/engine/install/

There are specific instructions for CentOS, Debian, Fedora and Ubuntu:

Docker runs natively on Linux and therefore does not require a hypervisor. Installation is done through the official package management system for the above distros. On other distros you have a couple hoops to jump through.

You may need to remove old versions first:

$ sudo apt-get remove docker docker-engine docker.io

The Docker CE version is newer than the docker.io version, and it's best to completely remove old traces before continuing.

For Ubuntu this is the official instructions:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get -y install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

This configures the OS to access the Docker package repository, then to install the Docker CE and Containerd packages. The last command tells Linux to automatically start Docker when the system boots.

For other Linux distros, see the official instructions page.

Post-install instruction for Linux

All versions of Linux have some post-install steps to make it more convenient to use Docker.

See: (docs.docker.com) https://docs.docker.com/install/linux/linux-postinstall/

$ sudo groupadd docker
$ sudo usermod -aG docker $USER

This adds a new group named docker. Any user in the docker group can freely run the Docker commands. Otherwise running Docker commands requires using sudo docker. Repeat the usermod command for each user ID that is to have access to the docker command.

Then we enable Docker to run in the background:

# for systemctl
$ sudo systemctl enable docker
# for upstart
$ echo manual | sudo tee /etc/init/docker.override
# for chkconfig
$ sudo chkconfig docker on

The next step is configuring Docker to launch when the system reboots. If you do not do this, you'll be required to start Docker manually before running any containers. By doing this we can treat any Docker container as a background daemon service.

Installing Docker Compose on Linux

Docker Compose is a very important part of the Docker ecosystem. Compose lets us easily launch and manage a group of Docker containers via use of a Docker Compose (YAML) file.

For the Windows and macOS platforms, Docker Compose is automatically installed. On Linux, however, we must install it separately.

See the documentation: (docs.docker.com) https://docs.docker.com/compose/

The official documentation gives a complex process for installing Compose on Linux. You might, however, find it in the regular package management system.

As of this writing some changes are occurring that may make docker-compose irrelevant. That's because of a new docker compose sub-command that seems to be intended to take its place.

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.