Install Docker Toolbox on a Mac via command line
Asked Answered
G

3

61

I am trying to automate setting up a developer environment on Mac. Part of that setup is installing the Docker Toolbox. I cannot find any documentation on how do to this via command line. How can I automate this installation (must be triggered via command line)?


Update: As pointed out in a commend by Dennis

Docker for Mac now exists, which is an alternative to Docker Toolbox. You can get it via the homebrew cask: brew cask install docker; open /Applications/Docker.app

Glovsky answered 23/9, 2015 at 16:25 Comment(3)
Note that Docker for Mac now exists, which is an alternative to Docker Toolbox. You can get it via the homebrew cask: brew cask install dockerShophar
After I run brew cask install docker, then I run docker and get -bash: docker: command not foundKatushka
Figured it out, you need open /Applications/Docker.appKatushka
G
94

Deprecation Warning

Docker Toolbox and Docker Machine have both been deprecated. Docker Desktop is the officially recommended replacement.

Original Answer

I found that Docker Toolbox is available via brew/cask

# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install Cask
brew install caskroom/cask/brew-cask
# Install docker toolbox
brew cask install docker-toolbox

Once Docker Toolbox is installed you can setup your docker environment using the Get started with Docker Machine guide.


# create the docker machine
docker-machine create --driver "virtualbox" myBoxName

# start the docker machine
docker-machine start myBoxName

# this command allows the docker commands to be used in the terminal
eval "$(docker-machine env myBoxName)"

# at this point can run any "docker" or "docker-compose" commands you want
docker-compose up

At the end of this process, add eval "$(docker-machine env myBoxName)" to your .bash_profile or you will get the following error when you open a new shell or terminal.

"Cannot connect to the Docker daemon. Is the docker daemon running on this host?"

If you start the docker container after opening the terminal, you can either run eval "$(docker-machine env myBoxName)" manually, or reload your bash profile (source ~/.bash_profile).

Glovsky answered 24/9, 2015 at 20:35 Comment(13)
Wouldn't you still need to go through the wizard-style setup after installing the cask?Shophar
@Dennis, No, you do not need to use the "wizard style setup". After installing you can use the command line to setup and configure anything docker related.Glovsky
Could you update your answer to complete the CLI setup instructions for Docker Toolbox? I'm guessing the missing steps are creating a default VM, starting it, and configuring the shell environment. In that case, we could also brew install docker docker-machine docker-compose instead of tapping the toolbox cask, no?Shophar
@Dennis, you are correct that the missing steps involve creating and setting up a default VM. I added a link to guide for doing this.Glovsky
@Dennis, docker-machine and docker-compose were not available as standalone packages the last time I looked. If they have been added, then that may indeed work.Glovsky
As an alternative to the last part of the guide, you can run open /Applications/Docker/Docker\ Quickstart\ Terminal.app which will create the default docker machine in virtualbox just like in the wizard-style setup.Jerold
The package is named "docker-toolbox" for me.Kalagher
What is myBoxName? Is that what you have to get by echoing your machine name?Empressement
1C02S21TWG8WMMBP:~ cchilders$ eval "$(docker-machine env myBoxName)" Host does not exist: "myBoxName"1Empressement
@Empressement <myBoxName> is the name of the docker machine that you created.Glovsky
It's worth mentioning you may need docker-machine-nfs github.com/adlogix/docker-machine-nfsDeuno
Docker Toolbox and Docker Machine have been deprecated.Entrant
@Entrant Good call out, I added a deprecation warning to the answer.Glovsky
D
9

Docker Toolbox is a good option but currently it seems like Docker for Mac/Windows is becoming better and Docker is investing a lot of time polishing the app. I recommend installing Docker mainly for 2 reasons:

  1. It doesn't interfere with Docker-Toolbox
  2. It runs on HyperKit and therefor runs on you own localhost rather than a Docker Machine IP.

The installation is quite simple:

brew cask install docker

To install docker-toolbox you can refer the above post

Drank answered 20/12, 2017 at 16:20 Comment(1)
Also, on a Mac, you get the System toolbar icon (which you don't get installing Toolbox by itself). So, I install both.Lubbi
D
7

Homebrew Updates

I can clear up a few things:

brew cask commands were deprecated on 2020-12-01 with the release of Homebrew 2.6.0. Starting then, all brew cask commands succeeded but displayed a warning informing users that the command would soon be disabled. The message also provides the appropriate replacement.
brew cask commands were disabled on 2020-12-21 with the release of Homebrew 2.7.0. Starting then, all brew cask commands failed and displayed a warning informing users that the command is disabled. The message also provides the appropriate replacement.

With the release of Homebrew 2.8.0 (release date TBD), this disable message will be removed.

 The alternative to brew cask <command> is to use brew <command>. In many cases, you can add the --cask flag to specify casks only. For example, brew cask install atom is now brew install atom or brew install --cask atom. There are some casks that share a name with formulae (e.g. wireshark) so adding --cask ensures that the cask is installed not the formula.

I'm not much of an ansible user but I'm happy to try and help out if needed. Feel free to point me in the right direction if anything is blocked and could use feedback from the Homebrew side of things.

Now you can run like

brew install --cask docker 
Diannediannne answered 28/12, 2020 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.