我正在尝试自动化在Mac上设置开发环境的过程。其中一部分是安装Docker Toolbox。我找不到任何关于如何通过命令行完成此操作的文档。如何自动化此安装(必须通过命令行触发)?
更新:正如Dennis在评论中指出的:
Docker for Mac现在已经存在,这是Docker Toolbox的替代方案。您可以通过homebrew cask获取它:
brew cask install docker; open /Applications/Docker.app
我正在尝试自动化在Mac上设置开发环境的过程。其中一部分是安装Docker Toolbox。我找不到任何关于如何通过命令行完成此操作的文档。如何自动化此安装(必须通过命令行触发)?
更新:正如Dennis在评论中指出的:
Docker for Mac现在已经存在,这是Docker Toolbox的替代方案。您可以通过homebrew cask获取它:
brew cask install docker; open /Applications/Docker.app
Docker Toolbox 和 Docker Machine 均已被弃用,Docker Desktop 是官方推荐的替代品。
我发现Docker Toolbox 可以通过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
一旦安装了Docker Toolbox,您可以使用开始使用Docker Machine指南设置docker环境。
# 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
在这个过程的最后,把 eval "$(docker-machine env myBoxName)"
添加到你的 .bash_profile
文件中,否则当你打开新的 shell 或终端时会出现以下错误:
"Cannot connect to the Docker daemon. Is the docker daemon running on this host?"
如果你在打开终端之后启动了 docker 容器,你可以手动运行 eval "$(docker-machine env myBoxName)"
,或者重新加载你的 bash 配置文件 (source ~/.bash_profile
)。
brew install docker docker-machine docker-compose
代替安装toolbox cask,对吗? - Dennisopen /Applications/Docker/Docker\ Quickstart\ Terminal.app
,这将在VirtualBox中创建默认的Docker虚拟机,就像向导式设置一样。 - jcugatDocker Toolbox是一个不错的选择,但目前似乎Docker for Mac / Windows正在变得更好,Docker正在投入大量时间来完善应用程序。我推荐安装Docker主要有两个原因:
安装非常简单:
brew cask install docker
要安装docker-toolbox,您可以参考上述帖子
Homebrew更新
我可以澄清一些事情:
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.
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.
brew install --cask docker
brew cask install docker
。 - Dennisbrew cask install docker
之后,我运行docker
命令,但是出现了“-bash: docker: command not found”的错误提示。 - samthebestopen /Applications/Docker.app
命令。 - samthebest