Appendix B. Installing Docker

Docker is a tool for running applications within containers on a particular machine. It is used throughout this book for running various databases, third-party services, and even applications that you write. Docker maintains an Install Docker Engine page, but the instructions for macOS and Linux have been repeated here for your reference.

macOS: Install Docker Desktop for Mac

The primary way to install Docker on macOS is by installing Docker Desktop for Mac. This will provide you with not only the Docker daemon and CLI tools, but it will also provide you with a GUI tool that runs in your menu bar. Visit the Docker Desktop for Mac page and download the stable disk image, then go through the usual macOS installation process.

Linux: Convenient Install Script

If you’re using an Ubuntu-based operating sytem, you can install Docker by adding the Docker repository to your system and installing with your package manager. This will allow Docker to remain updated by doing normal package upgrade operations.

Docker provides a convenient script that will do several things. First, it’ll configure your Linux distribution’s package manager to use the Docker repository. The script supports several distros like Ubuntu and CentOS. It’ll also install the necessary packages from the Docker repository to your local machine. When you perform package upgrades in the future, your machine will also update Docker:

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

If you’d like to control Docker from your current account without needing to provide sudo all the time, run the following commands. The first will add your user to a docker group, and the second will apply the new group within your terminal session (though you’ll need to log out and back in for the changes to be applied globally):

$ sudo usermod -aG docker $USER
$ su - $USER

You’ll also need to install docker-compose to run examples from several sections in this book. Currently you need to add it separately, because it’s not provided in the Docker repository. Run the following commands to download a precompiled binary and to make it executable:

$ sudo curl -L "https://github.com/docker/compose/releases/download\
/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
  -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose