As part of my job at Workiva I work quite a bit with containers and I need to install Docker Desktop on my Mac running Big Sur. Instead of just downloading and installing the DMG from Docker, I instead wanted to install just the command line with Homebrew.
The first step, of course, is to install Homebrew. I won’t replicate those instructions here. Once you’ve done that and checked the installation, proceed with the following instructions.
Install docker and docker-machine
Install the actual docker and docker-machine packages using Homebrew:
brew install docker docker-machine
Install virtualbox
Docker will need a virtualization system for running containers, I use virtualbox. Install it using Homebrew:
brew install virtualbox
You may need to provide your administrator password to complete the installation. In addition, you will also probably need to allow the virtualbox system extension permission to run. A popup will open the Security & Privacy tab in System Preferences. Authenticate if needed and allow the extension to run. A restart will be required to load the extension.
Configure docker and docker-machine
The next step is to configure docker-machine to use virtualbox as the default virtualization environment:
docker-machine create --driver virtualbox default
After a bunch of output, a default configuration environment will be available, and the docker daemon will be running with the default environment. You can list the default machine with the docker-machine ls
command.
To configure the docker command which docker-machine instance to use, execute the following command in your terminal:
eval $(docker-machine env default)
Finally, test to make sure that everything is installed correctly by running the hello-world container. Docker will download the container from Docker Hub and you should see output from the container:
docker run hello-world
Starting and stopping the docker-machine
I prefer to control when the docker-machine is running. Use the following commands to start and stop the background docker daemon:
docker-machine start default
docker-machine stop default
Shell aliases
I have a few aliases defined in my .zshrc to help control docker-machine and configure docker:
# docker commands
alias dm-up="docker-machine start default; eval \$(docker-machine env default)"
alias dm-down="docker-machine stop default"
alias d-config="eval \$(docker-machine env default)"
It’s always best to reconfigure docker after starting the machine in case new IP addresses have been allocated. Also, I prefer up and down instead of start and stop for some odd reason.