How to install Docker on MacOS

 by Robin Wieruch
 - Edit this Post

Just recently I had to install Docker on my MacOS machine. Here I want to give you a brief walkthrough on how to achieve it. First of all, we need Homebrew to install all the necessary Docker dependencies. If there isn't a Homebrew installation on your Mac, follow .

Install the docker dependency with Homebrew after making sure that all Homebrew dependencies are on the latest version:

brew update
brew install docker

You will also need a MacOS specific environment in which Docker can be used, because natively Docker uses a Linux environment. Therefore, install the docker-machine and virtualbox dependencies:

brew install docker-machine
brew install --cask virtualbox

Note: If the last install fails, check your MacOS' System Preference and verify if System software from developer "Oracle America, inc" was blocked from loading. shows up. If you see it, hit the "Allow"-button and install it again.

Optional: if you want to use Docker Compose later, install the docker-compose dependency with Homebrew:

brew install docker-compose

Everything related to Docker and its environment is installed now. Let's get started with using it. First, create an engine for Docker on MacOS. This needs to be done only once, unless you want to create more than one engine by giving them other names than default. Usually one engine should be sufficient.

docker-machine create --driver virtualbox default

Using the following command for your Docker Machine, you should see whether your last Docker engine got created and whether you have more than one engine if desired:

docker-machine ls
default - virtualbox Stopped Unknown

Usually the Docker engine's STATE should be Running. If it isn't, like it's shown in the last output, you can start the engine with Docker Machine:

docker-machine start default

Checking your list of Docker engines again should lead you to one running Docker engine:

docker-machine ls
default - virtualbox Running tcp:// v19.03.5

Just for the sake of knowing about it, you can stop your Docker engine anytime too:

docker-machine stop default

Make sure that your Docker engine is running for the next steps. Last, we need to configure the environment variables for Docker. Run the following command to find out how:

docker-machine env default
export DOCKER_HOST="tcp://"
export DOCKER_CERT_PATH="/Users/mydspr/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)

Usually this prints out the command to set all the env variables set for MacOS; which is the following:

eval $(docker-machine env default)

Finally, you should be able to start a Docker container with a pre-defined Docker image to check whether everything works as expected:

docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

The first time running this command should take some time, because the pre-defined Docker image is pulled from a remote server. Every additional time you run this command, it should print its output almost in an instant, because the Docker image is already there and the build for the Docker container from the Docker image doesn't take long for this example. Congratulations, Docker is running on your Mac machine now.

This tutorial is part 1 of 2 in the series.

This tutorial is part 1 of 2 in the series.

This tutorial is part 1 of 2 in the series.

Continue Reading:

Keep reading about 

A collection of all the Docker commands I am using on a regular basis for developing applications with Docker. Docker Machine List all Docker engines: Create a Docker engine: Set environment variables…

Docker Compose helps you run multi-container applications. In this tutorial, we expand a Docker project, which has only a Dockerfile, with Docker Compose. Before you continue, make sure you have set…

The Road to React

Learn React by building real world applications. No setup configuration. No tooling. Plain React in 200+ pages of learning material. Learn React like 50.000+ readers.

Get it on Amazon.