273

Trying to setup docker from brew, however the engine does not seem to be included in any of the any of the official formulas.

brew install docker-machine docker-compose

So these only installs the clients? Is there no keg with the engine/daemon?

nwinkler
  • 52,665
  • 21
  • 154
  • 168
David Karlsson
  • 9,396
  • 9
  • 58
  • 103

7 Answers7

545

The following steps work fine on macOS Sierra 10.12.4. Note that after brew installs Docker, the docker command (symbolic link) is not available at /usr/local/bin. Running the Docker app for the first time creates this symbolic link. See the detailed steps below.

  1. Install Docker.

    brew install --cask docker
    
  2. Launch Docker.

    • Press + Space to bring up Spotlight Search and enter Docker to launch Docker.
    • In the Docker needs privileged access dialog box, click OK.
    • Enter password and click OK.

    When Docker is launched in this manner, a Docker whale icon appears in the status menu. As soon as the whale icon appears, the symbolic links for docker, docker-compose, docker-credential-osxkeychain and docker-machine are created in /usr/local/bin.

    $ ls -l /usr/local/bin/docker*
    lrwxr-xr-x  1 susam  domain Users  67 Apr 12 14:14 /usr/local/bin/docker -> /Users/susam/Library/Group Containers/group.com.docker/bin/docker
    lrwxr-xr-x  1 susam  domain Users  75 Apr 12 14:14 /usr/local/bin/docker-compose -> /Users/susam/Library/Group Containers/group.com.docker/bin/docker-compose
    lrwxr-xr-x  1 susam  domain Users  90 Apr 12 14:14 /usr/local/bin/docker-credential-osxkeychain -> /Users/susam/Library/Group Containers/group.com.docker/bin/docker-credential-osxkeychain
    lrwxr-xr-x  1 susam  domain Users  75 Apr 12 14:14 /usr/local/bin/docker-machine -> /Users/susam/Library/Group Containers/group.com.docker/bin/docker-machine
    
  3. Click on the docker whale icon in the status menu and wait for it to show Docker is running.

    enter image description here enter image description here

  1. Test that docker works fine.

    $ docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    78445dd45222: Pull complete
    Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/
    
    $ docker version
    Client:
     Version:      17.03.1-ce
     API version:  1.27
     Go version:   go1.7.5
     Git commit:   c6d412e
     Built:        Tue Mar 28 00:40:02 2017
     OS/Arch:      darwin/amd64
    
    Server:
     Version:      17.03.1-ce
     API version:  1.27 (minimum version 1.12)
     Go version:   go1.7.5
     Git commit:   c6d412e
     Built:        Fri Mar 24 00:00:50 2017
     OS/Arch:      linux/amd64
     Experimental: true
    
Susam Pal
  • 32,765
  • 12
  • 81
  • 103
  • This is great! Now I'm just stuck at User X isn't part of the docker group. What's the current way to fix that? – Alper Jan 03 '19 at 10:56
  • I'm stuck at Docker Desktop for Mac being tied to running with the user logged into the Mac OS UI. It's not possible to `open /Applications/Docker.app` remotely to start using docker. And if you do sign out, it stops the app and the engine and all its containers. – dlamblin Mar 06 '19 at 04:28
  • 2
    `brew cask install docker` command not work. it works `brew install homebrew/cask/docker` or `brew install --cask docker` docker install but its not showing in application by click command and space bar. – Avinash Dalvi May 21 '21 at 18:50
  • 2
    is using brew to install docker really recommended or safe? – Charlie Parker Jun 06 '22 at 17:30
  • 1
    this is a great answer, with a ton of transparency into the whole setup process. thank you! – jamesdlivesinatree Apr 04 '23 at 18:49
  • 2
    Docker CLI tools are installed under $HOME/.docker/bin -- so `docker` is not available on the CLI by default. You can update your PATH or go to Docker Desktop settings -> Advanced -> select "System (Requires password)" – northben Apr 11 '23 at 16:32
324

Please try running

brew install docker

This will install the Docker engine, which will require Docker-Machine (+ VirtualBox) to run on the Mac.

If you want to install the newer Docker for Mac, which does not require virtualbox, you can install that through Homebrew's Cask:

brew install --cask docker 
open /Applications/Docker.app
Exploring
  • 2,493
  • 11
  • 56
  • 97
nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • 1
    'docker-compose' up just gives me: an error "you might need to run docker-machine start default" I do not want to run a virtual box for my containers, I want to run it locally on my mac – David Karlsson Nov 10 '16 at 09:19
  • 4
    I've updated my answer to show how to install Docker for Mac, which does not require VirtualBox or Docker-Machine. – nwinkler Nov 10 '16 at 11:33
  • 2
    I can see that this gives me the entire desktop app. Is there no way to get the daemon+cli tools only, I want to run it on a "headless" OSX. – David Karlsson Nov 10 '16 at 11:57
  • For running Docker on macOS, you either need Docker-Machine (+ VirtualBox), or the "native" Docker for Mac (which internally starts a small VM as well from what I understand). – nwinkler Nov 10 '16 at 12:01
  • 23
    @DavidKarlsson The GUI app is the "official" Docker app, Docker Inc. provies no headless package for Mac OS. However, the GUI app contains the command line utilities. If the `brew cask install docker` does not create symlinks in `usr/local/bin` you can create them yourself: `ln -s /Applications/Docker.app/Contents/Resources/bin /usr/local/bin/docker` – chiborg Jan 16 '17 at 16:06
  • @chiborg -- thank you for that extra tidbit regarding the symbolic link, definitely needed! – xmnboy Apr 05 '17 at 21:31
  • But this is the command-line that worked for me: `ln -s /Applications/Docker.app/Contents/Resources/bin/docker /usr/local/bin/` – xmnboy Apr 05 '17 at 21:45
  • 20
    It is not necessary to create the symbolic links to docker binaries manually. Running Docker app for the first time creates these symbolic links. See my answer at http://stackoverflow.com/a/43365425/303363 for details. – Susam Pal Apr 12 '17 at 09:29
  • 1
    You need also `open /Applications/Docker.app` otherwise `docker` will just give `command not found`, I'll edit. – samthebest Feb 05 '20 at 16:20
  • 6
    `brew cask install docker` is deprecated and `brew install docker` installs docker CLI. To install the docker for desktop, run `brew install --cask docker` – vijaycs85 Dec 27 '20 at 19:40
  • This worked for me as well, I just had to uninstall docker and docker desktop first, then reinstalling them and docker worked for me again – davidawad Jan 13 '21 at 17:35
  • same; `brew uninstall docker && brew install --cask docker` worked for me. – John Targaryen Apr 13 '22 at 01:37
  • is using brew to install docker really recommended or safe? – Charlie Parker Jun 06 '22 at 17:31
  • My experience with Docker Desktop is mixed. I got a daily nag from it which I think stopped when I shut off automatic updates. It also broke python. The docker-compose python was first on my path and broken when I run "python" from the command line. To get both docker-compose and python both working, I had to put docker-compose either at the start or end of my PATH. I created an alias for docker-compose in my .bashrc which altered the PATH before running it. The benefit of docker desktop is that it adds a thin UI on top of docker - and that they maintain a new version of docker. – Curtis Yallop Jun 21 '22 at 17:04
  • Note that docker on the Mac (or Windows) runs 1 VM per container. This is fine for 1 container but could get heavyweight if you want to run 10 containers. Under Linux, each docker container runs in 1 process. – Curtis Yallop Jun 21 '22 at 17:06
  • The link in your answer which is supposed to provide an explanation of why "Docker Desktop" (previously called "Docker for Mac" or "Docker for Windows") does not require VirtualBox actually mentions that it is incompatible with a certain older versions of VirtualBox. And as mentioned here: https://docs.docker.com/desktop/vm-vdi/ "... Docker Desktop is using a Linux VM in which it runs Docker Engine and the containers." So, it requires some kind of virtual machine hypervisor to run. – Peter Bašista Aug 23 '22 at 08:53
47

To install Docker for Mac with homebrew:

brew install homebrew/cask/docker

To install the command line completion:

brew install bash-completion
brew install docker-completion
brew install docker-compose-completion
brew install docker-machine-completion
Brad
  • 15,361
  • 6
  • 36
  • 57
wisbucky
  • 33,218
  • 10
  • 150
  • 101
  • 12
    you don't want `brew install docker` -- this is not the same as `brew cask install docker` and installs different things @mimoralea – Igor Serebryany Dec 05 '18 at 21:10
  • 4
    Thanks for the heads-up: `brew cask install docker && brew install bash-completion docker-completion docker-compose-completion docker-machine-completion` – mimoralea Dec 06 '18 at 16:49
  • Don't use docker-machine - it will gives you a lot of headache with network forwarding – Vlad Jan 07 '19 at 20:40
  • 1
    @mimoralea I would suggest you delete your first comment, so everyone spots your second one :-) – Duncan Jones Feb 07 '19 at 15:18
  • 2
    @IgorSerebryany why are they different? what is the difference between them? I would expect the docker daemon be there either way, and work cli - is the difference only that one (cask) has kitematic as well? – linuxbandit Mar 05 '19 at 16:57
  • You should leave the completion related things to the Docker cask and not use these, in fact, if `docker-completion` or `docker-compose-completion` is installed beforehand, it will conflict with the cask. Just run `brew install --cask docker` and run `Docker.app`, it will deal with the completions itself. – Menace Dec 03 '21 at 15:00
12

Docker desktop will not be installed if you run brew install docker. If you've already installed it this way, first uninstall with brew uninstall docker.

To install Docker Desktop, run:

brew install homebrew/cask/docker

Launch docker from your /Applications folder once and enter your password, then you can run commands like docker --version to verify the CLI is working.

giraffesyo
  • 4,860
  • 1
  • 29
  • 39
11

Docker Desktop for Mac is not a suitable choice for enterprise docker users as it requires a paid license to use. Rancher Desktop is a viable open-source alternative for Docker Desktop for all three major OS.

Since this question is specifically targeted at Mac OS users, I have added the steps to make it work on Mac OS.

  1. First install Docker using homebrew. brew install docker

  2. Install Rancher Desktop.

  3. In Kubernates Settings, change container runtime to dockerd.

Profit !

UPDATE: There's another open-source container runtime in the scene, named Colima (https://github.com/abiosoft/colima).

Pavindu
  • 2,684
  • 6
  • 44
  • 77
  • Does Rancher replace the need for `docker-machine` and hence obviates the need for `virtualbox`? – NeilG Jul 05 '22 at 12:53
  • 1
    @NeilG Yes it does. – Pavindu Jul 05 '22 at 13:14
  • 3
    Yes indeed. On an M1 Mac on version 12.4 Monterey the following commands worked: `softwareupdate --install-rosetta` - `brew install docker` - `brew install --cask rancher` - `open /Applications/Rancher\ Desktop.app/` - `docker run hello-world`. I chose "dockerd (moby)" as the container runtime. I'm not sure if rosetta is required. I had already installed it and wasn't able to check whether it was required or not. – NeilG Jul 05 '22 at 13:29
2

For reinstall docker, you should run:

brew reinstall homebrew/cask/docker
Zhang Buzz
  • 10,420
  • 6
  • 38
  • 47
0

There is now alternative to Docker Desktop for Mac: colima

If you have Homebrew installed, you can install it using:

brew install colima docker
colima start

docker installs Docker client, while colima provides the daemon.

Mitar
  • 6,756
  • 5
  • 54
  • 86