通过命令行在 Mac 上安装 Docker 工具箱
Install Docker Toolbox on a Mac via command line
我正在尝试在 Mac 上自动设置开发人员环境。该设置的一部分是安装 Docker Toolbox。我找不到任何关于如何通过命令行执行此操作的文档。如何自动执行此安装(必须通过命令行触发)?
更新: 正如
的表扬所指出的
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
弃用警告
Docker Toolbox and Docker Machine have both been deprecated. Docker Desktop是官方推荐的替换。
原答案
我发现 Docker 工具箱可通过 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 后,您可以使用 Get started with 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
).
Docker Toolbox 是一个不错的选择,但目前看来 Docker for Mac/Windows 变得越来越好,Docker 正在投入大量时间完善应用程序。我推荐安装 Docker 主要有两个原因:
- 它不会干扰 Docker-工具箱
- 它在 HyperKit 上运行,因此在您自己的本地主机上运行,而不是 Docker 机器 IP。
安装非常简单:
brew cask install docker
要安装 docker-toolbox 你可以参考 post
自制软件更新
我可以弄清楚一些事情:
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.
随着 Homebrew 2.8.0 的发布(发布日期待定),此禁用消息将被删除。
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.
我不是一个 ansible 用户,但我很乐意尝试并在需要时提供帮助。如果有任何问题,请随时为我指出正确的方向,并且可以使用 Homebrew 方面的反馈。
现在您可以运行喜欢
brew install --cask docker
我正在尝试在 Mac 上自动设置开发人员环境。该设置的一部分是安装 Docker Toolbox。我找不到任何关于如何通过命令行执行此操作的文档。如何自动执行此安装(必须通过命令行触发)?
更新: 正如
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
弃用警告
Docker Toolbox and Docker Machine have both been deprecated. Docker Desktop是官方推荐的替换。
原答案
我发现 Docker 工具箱可通过 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 后,您可以使用 Get started with 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
).
Docker Toolbox 是一个不错的选择,但目前看来 Docker for Mac/Windows 变得越来越好,Docker 正在投入大量时间完善应用程序。我推荐安装 Docker 主要有两个原因:
- 它不会干扰 Docker-工具箱
- 它在 HyperKit 上运行,因此在您自己的本地主机上运行,而不是 Docker 机器 IP。
安装非常简单:
brew cask install docker
要安装 docker-toolbox 你可以参考
自制软件更新
我可以弄清楚一些事情:
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.
随着 Homebrew 2.8.0 的发布(发布日期待定),此禁用消息将被删除。
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.
我不是一个 ansible 用户,但我很乐意尝试并在需要时提供帮助。如果有任何问题,请随时为我指出正确的方向,并且可以使用 Homebrew 方面的反馈。
现在您可以运行喜欢
brew install --cask docker