Installing Docker is easy, but there are some details you may want to consider before you download and run the installer.
In this tutorial, we'll focus on:
- Why Linux is Docker’s native environment
- The difference between Docker edge vs. Docker stable
- Why Docker for non-Linux requires a VM
Install Docker on macOS, Windows, or Linux.
Bare metal, the host OS, and the guest OS
Whenever we talk about virtualization or containerization it can be difficult to know if we're talking about the VM, our OS, or the real physical hardware that we're using. Fortunately, there's some terminology that can help us.
Imagine that you've built a computer yourself. You've selected each component, assembled them, and then powered it all on. If you've done this before you know that it won't get very far. Shortly after flipping the switch the monitor will say that it cannot find the operating system or boot disk. When we refer to a computer's physical hardware, devoid of any operating system, we call it the bare metal system. It's obvious, but no VM or container can exist without bare metal supporting it.
When we use a boot disk or a USB stick to install an operating system on bare metal, we're installing the host OS. The host OS supports all the utilities and applications we'll run on that system.
When we run a virtual machine on our system, we're running a completely separate operating system on top of the one we installed previously. This additional operating system is called the guest OS. You can think about it like holding a party for your friends. When you run the party and invite them to your home, you're the host and your friends are the guests. Likewise, the host OS allows for the guest OS to run on the bare metal. The guest OS relies on a piece of software on the host called a hypervisor, which runs the virtual machine.
There are lots of hypervisors out there including VMWare, Parallels, Hyper-V, and Oracle VirtualBox.
Linux and Docker
In many ways, Linux is Docker's native environment. While Docker can run Windows applications within a container, the vast majority of containers run an application designed for Linux. This is perfect for us as most web servers that run Drupal sites in production use the Linux operating system.
There are many different distributions of Linux. Ubuntu, Debian, and Red Hat are just a few. Each of these distributions, however, all rely on the same core component -- the Linux kernel. The kernel provides the core APIs necessary to run a Linux application. The differences in distributions relate to the utilities necessary to create an execution environment for an application.
Docker doesn't favor one distribution of Linux over another. Instead, it provides a Linux kernel, and lets each container decide what distribution of Linux it needs. This approach works great on systems that are running Linux on the bare metal. Since a kernel is already on the system, Docker only needs to sandbox any container it runs from the host OS.
Docker on macOS and Windows
What happens when we need to run Docker on a host OS that isn't Linux? Most of us run either macOS or Windows. Can Docker still run Linux containers here?
The answer is "yes!" But there's a condition. In order to provide a Linux kernel on macOS and Windows, we need a virtual machine. Docker provides this virtual machine differently on each non-Linux OS it supports:
- Docker for Mac uses Hyperkit. Hyperkit is an embedded, open source hypervisor. Hyperkit is included out of the box with Docker for Mac, so no additional installation is required.
- Docker for Windows requires Microsoft Hyper-V. Hyper-V is free to install for any Windows Pro or Windows Server installation.
- Docker Machine is an older alternative for macOS and Windows. It relies on Oracle Virtualbox to provide a hypervisor.
Wait, we need a VM?
If we're running a non-Linux OS, we need a Linux VM to run Docker. Doesn't that mean we'll have all the same problems that come with VMs?
Yes and no. The VM that Docker relies on is specifically tailored to only run Docker containers. It contains little more than the Linux Kernel and internal utilities needed by Docker itself. Furthermore, one Docker VM can run as many containers as your bare metal can support. This is true regardless of the distribution each container requires.
This design keeps resource consumption low, but leverages proven technologies to sandbox your containers from each other.
Choose an edition
There are 2 editions of Docker for you to choose between.
Docker Community Edition (CE) is completely free and open source. It provides the runtime and all utilities necessary to build and run containers. Most Drupal developers will run Docker CE on their laptops.
Docker Enterprise Edition (EE) relies on the same runtime and utilities as Docker CE, but adds key features for running mission-critical applications. It allows you to run certified plugins and containers, integrates with other products like Docker Datacenter, and includes same-day support. If you plan on running Docker in production, you may want to consider Enterprise Edition.
Choose a channel
Docker also comes in 2 channels.
Docker Stable, as its name implies, is the current, stable version of Docker. It has been tested to show that all major bugs are known, and it is expected to not break any existing containers.
Docker Edge can be thought of as a beta version of Docker. It contains the most recent features and enhancements, but may not be free of major bugs or compatibility issues. The Edge version updates more frequently than Stable.
Most Drupal developers will only need Docker Stable. Only use the Edge version if you expect to leverage new features or require a key performance improvement the Edge version provides.
Get the installer
Docker for Mac and Docker for Windows are available on Docker.com. Select the edition and channel of your choice, then run the installer.
To install Docker on Linux, consult your distribution's documentation. Typically, Docker is available in your system's default package manager.
Potential conflicts with other products
When running Docker on your system, it's best to shut down or disable other potentially conflicting products and services.
Docker containers that run web server applications typically allocate the same network ports. For this reason, it's best to shut down MAMP, WAMP, Acquia Dev Desktop, and any other all-in-one web development environments. This prevents port conflicts and confusing user errors.
If you have any hypervisors on your system such as VMware or Parallels, it's best to not run them at the same time as Docker. Furthermore, if you are not running Docker Machine, shut down Oracle Virtualbox and Microsoft Hyper-V. These will consume additional resources on your system and could lead to performance problems.
Installing Docker isn't a difficult task, but it does require a small amount of thought before double-clicking the installer. We've learned about Docker's editions and channels, how to find the installers, and potential conflicts with other software that we can avoid.
Further your understanding
- What are cases where we would want to run a VM and a container at the same time?
- Download Docker Community Edition (docker.com)
- General installation docs (docker.com)
- Installing on macOS (docker.com)
- Installing on Windows (docker.com)
- Installing on Ubuntu (docker.com)