Docker for Mac vs. Docker Toolbox

96
Veekend
2017.01.13 16:03* 字数 2649

以下原文转载于(https://docs.docker.com/docker-for-mac/)(想找中文版的最新文档,最后发现还是直接看英文的靠谱。ps:本人英文很渣,以下翻译纯属Google加上一些修改来让我省些时间重新看英文,翻译仍需花时间精改。有问题欢迎评论提出,谢谢0.0)

If you already have an installation of Docker Toolbox, please read these topics first to learn how Docker for Mac and Docker Toolbox differ, and how they can coexist.
(如果你已安装了Docker Toolbox,请先阅读下列标题来学习Docker和Docker Toolbox的不同之处,并且如何使它们共存)

The Docker Toolbox environment
Docker Toolbox installs <code>docker</code>,<code>docker-compose </code>and <code>docker -machine</code> in <code>/usr/local/bin</code> on your Mac. It also installs VirtualBox. At installation time, Toolbox uses <code>docker -machine</code> to provision a VirtualBox VM called <code>default</code>, running the <code>boot2docker</code> Linux distribution, with Docker Engine with certificates located on your Mac at <code>$HOME/.docker/machine/machines/default</code>.
(Docker Toolbox在Mac的<code>/usr/local/bin</code>目录下安装了<code>docker</code>,<code>docker-compose </code>and <code>docker -machine</code>。它也安装了VirtualBox。在安装过程中,Toolbox通过<code>docker -machine</code>命令,使用Docker Engine(其证书位于 <code>$HOME/.docker/machine/machines/default</code>.)来配置了一个名称为<code>default</code>的VirtualBox VM,它运行<code>boot2docker</code>Linux发行版,)

Before you use <code>docker</code> or <code>docker-compose</code> on your Mac, you typically use the command <code>eval $(docker-machine env default)</code> to set environment variables so that <code>docker</code> or <code>docker-compose</code> know how to talk to Docker Engine running on VirtualBox.
(在你使用<code>docker</code>或者<code>docker-compose</code>命令之前,你需要键入命令<code>eval $(docker-machine env default)</code>来设置环境变量来使<code>docker</code>或者<code>docker-compose</code>命令知道如何让Docker Engine运行在VirtualBox上)

This setup is shown in the following diagram.

Docker Toolbox Install
Docker Toolbox Install

The Docker for Mac environment
Docker for Mac is a Mac native application, that you install in <code>/Applications</code>
. At installation time, it creates symlinks in <code>/usr/local/bin</code> for <code>docker</code> and <code>docker-compose</code>, to the version of the commands inside the Mac application bundle, in<code>/Applications/Docker.app/Contents/Resources/bin</code>.
(Docker for Mac是MAC中原生APP,你可以安装在<code>/Applications</code>目录下,安装过程中,它在Mac程序包中为<code>docker</code>和<code>docker-compose</code>创建了与<code>/usr/local/bin</code>的命令行版本的符合链接,)

Here are some key points to know about Docker for Mac before you get started:
(下面是在你启动Docker for Mac前须知的一些关键点:)
Docker for Mac does not use VirtualBox, but rather HyperKit, a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher.
(Docker for Mac不使用VirtualBox,而是使用HyperKit,一个轻量级的macOS虚拟化解决方案,它在MacOS 10.10 Yosemite及更高版本中的Hypervisor.framework中编译)

Installing Docker for Mac does not affect machines you created with Docker Machine. The install offers to copy containers and images from your local default machine (if one exists) to the new Docker for Mac HyperKit VM. If chosen, content from default is copied to the new Docker for Mac HyperKit VM, and your original default machine is kept as is.
(安装Docker for Mac不会影响使用Docker Machine创建的machines,安装提供了从你本地默认的machines(如果存在的话)的容器和镜像复制到新的Docker for Mac的HyperKit VM中。如果被选中,内容会被复制到Docker for Mac的HyperKit VM中,而原来默认的machine仍然保持原来样子)

The Docker for Mac application does not use <code>docker-machine</code> to provision that VM; but rather creates and manages it directly.
(Docker for Mac不使用<code>docker-machine</code>来配置VM,但它直接创建和管理它)

At installation time, Docker for Mac provisions an HyperKit VM based on Alpine Linux, running Docker Engine. It exposes the docker API on a socket in <code>/var/run/docker.sock</code>. Since this is the default location where docker will look if no environment variables are set, you can start using <code>docker</code> and <code>docker-compose</code> without setting any environment variables.
(安装过程中,Docker for Mac根据AIpine Linux,运行Docker Engine来配置HyperKit VM,它在<code>/var/run/docker.sock</code>中暴露出docker的API,因此这是docker如果没有设置环境变量下所映射的默认目录。你可以在没有设置任何环境变量的情况下使用<code>docker</code>和<code>docker-compose</code>来启动)

This setup is shown in the following diagram.


Docker for Mac Install
Docker for Mac Install

With Docker for Mac, you get only one VM, and you don’t manage it. It is managed by the Docker for Mac application, which includes autoupdate to update the client and server versions of Docker.
(你通过Docker for Mac仅可换取一个VM,并且你不可以管理它,它是由Docker应用来管理,此应用包含自动更新Docker的客户端和服务端)

If you need several VMs and want to manage the version of the Docker client or server you are using, you can continue to use <code>docker-machine</code>, on the same machine, as described in Docker Toolbox and Docker for Mac coexistence.
(在同一个machine上,如果你需要数个VM,并且想管理你正在使用的Docker的客户端和服务端,你可以继续使用<code>docker-machine</code>,参考Docker Toolbox and Docker for Mac coexistence

Setting up to run Docker for Mac
Check whether Toolbox DOCKER environment variables are set:
(检查Toolbox DOCKER环境变量是否已设置:)
<pre>
$ env | grep
DOCKER DOCKER_HOST=tcp://192.168.99.100:2376 DOCKER_MACHINE_NAME=default
DOCKER_TLS_VERIFY=1 DOCKER_CERT_PATH=/Users/victoriabialas/.docker/machine/machines/default
</pre>

If this command returns no output, you are ready to use Docker for Mac.
(如果命令没有输出返回,你需要使用Docker for Mac)
If it returns output (as shown in the example), you need to unset the DOCKER environment variables to make the client talk to the Docker for Mac Engine (next step).
(如果它像例子一样返回输出,你需要取消DOCKER的环境变量的设置来让客户端连接上Docker for Mac Engine (next step))

Run the <code>unset</code> command on the following DOCKER environment variables to unset them in the current shell.
(对以下DOCKER环境变量运行<code>unset</code>来让它们在当前的shell中失效)
<pre>
unset DOCKER_TLS_VERIFY
unset DOCKER_CERT_PATH
unset DOCKER_MACHINE_NAME
unset DOCKER_HOST
</pre>

Now, this command should return no output.
(现在,这条命令应该无输出返回)
<pre>
$ env | grep DOCKER
</pre>

If you are using a Bash shell, you can use <code>unset ${!DOCKER_}</code> to unset all DOCKER environment variables at once. (This will not work in other shells such as zsh; you will need to unset each variable individually.)
(如果你正在使用Bash shell,你可以使用<code>unset ${!DOCKER_
}</code>来使DOCKER环境变量马上失效(这在如zsh这些其他的shell中是不起作用的,你可以单独地为每一个变量都设置无效))

Note: If you have a shell script as part of your profile that sets these DOCKER environment variables automatically each time you open a command window, then you will need to unset these each time you want to use Docker for Mac.
提示:如果你有一个shell脚本作为你配置文件中的一部分,每次你一打开命令行窗口时都会自动设置这些环境变量,那么你每次想使用Docker for Mac时需要unset这些环境变量)

Warning: If you install Docker for Mac on a machine where Docker Toolbox is installed, it will replace the docker and <code>docker-compose</code> command lines in /usr/local/bin with symlinks to its own versions.
Warning:如果你在一个已安装Docker Toolbox的机器上再安装Docker for Mac,它会覆盖docker并且<code>docker-compose</code>命令会链接到它自己版本的<code>/usr/local/bin</code>中)

Docker Toolbox and Docker for Mac coexistence
You can use Docker for Mac and Docker Toolbox together on the same machine. When you want to use Docker for Mac, make sure all DOCKER environment variables are unset. You can do this in bash with <code>unset ${!DOCKER_}</code>. When you want to use one of the VirtualBox VMs you have set with <code>docker-machine</code>, just run a <code>eval $(docker-machine env default)</code> (or the name of the machine you want to target). This will switch the current command shell to talk to the specified Toolbox machine.
(你可以在同一台机器上使用Docker for Mac和Docker Toolbox。当你想要使用Docker for Mac,确保所有的DOCKER环境变量失效,你可以使用<code>unset ${!DOCKER_
}</code>来实现。当你想要使用其中一个VirtualBox VMs时,你需要使用<code>docker-machine</code>,只需要运行<code>eval $(docker-machine env default)</code>即可(或者你想要指定的目标的名称)。这会根据当前的命令来选择特定的Toolbox machine)

This setup is represented in the following diagram.


Docker Toolbox and Docker for Mac coexistence
Docker Toolbox and Docker for Mac coexistence

Using different versions of Docker tools
The coexistence setup works as is as long as your VirtualBox VMs provisioned with docker-machine run the same version of Docker Engine as Docker for Mac. If you need to use VMs running older versions of Docker Engine, you can use a tool like Docker Version Manager to manage several versions of docker client.
(运行的Docker Engine和Docker for Mac版本相同,只要使用VirtualBox VMs使用<code>docker-machine</code>来进行配置,就可以共存并正常工作。如果你需要使用VMs运行更旧版本的Docker Engine,你需要Docker Version Manager这样的工具来管理不同版本的docker客户端)

Checking component versions
Ideally, the Docker CLI client and Docker Engine should be the same version. Mismatches between client and server, and among host machines you might have created with Docker Machine can cause problems (client can’t talk to the server or host machines).
(理想情况下,Docker CLI客户端和Docker Engine应该保持版本相同。客户端和服务端之间以及你使用Docker Machine创建的主机之间存在的不匹配可能会导致问题(客户端无法与服务端或者主机进行通信))

If you already have Docker Toolbox installed, and then install Docker for Mac, you might get a newer version of the Docker client. Run <code>docker version</code> in a command shell to see client and server versions. In this example, the client installed with Docker for Mac is Version: 1.11.1
and the server (which was installed earlier with Toolbox) is Version: 1.11.0.
(如果你已经安装了Docker Toolbox,然后又安装了Docker for Mac,你可能想获取一个更新版本的Docker客户端,在命令行shell中运行<code>docker version</code>来查看客户端和服务端的版本。在这个例子中,Docker for Mac中的客户端版本为1.11.1)
<pre>
$ docker versionClient:Version: 1.11.1...Server:Version: 1.11.0...
</pre>

Also, if you created machines with Docker Machine (installed with Toolbox) then upgraded or installed Docker for Mac, you might have machines running different versions of Engine. Run <code>docker-machine ls</code> to view version information for the machines you created. In this example, the DOCKER column shows that each machine is running a different version of server.
(此外,如果你使用Toolbox安装的Docker Machine来创建machines,然后升级或安装Docker for Mac,你可能会存在运行着不同版本的Engine的machines,使用<code>docker-machine ls</code>来查看你创建的machines的版本信息,在这个例子中,DOCKER列会显示每一个machine正在运行不同版本的服务)
<pre>
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
aws-sandbox - amazonec2 Running tcp://52.90.113.128:2376 v1.1
0.0
default * virtualbox Running tcp://192.168.99.100:2376 v1.1
0.1
docker-sandbox - digitalocean Running tcp://104.131.43.236:2376 v1.1
0.0
</pre>

You might also run into a similar situation with Docker Universal Control Plan (UCP).
(你也可能遇到类似的情况与Docker通用控制计划(UCP)。)

There are a few ways to address this problem and keep using your older machines. One solution is to use a version manager like DVM.
(有几种方法来解决这个问题并继续使用旧机器。 一个解决方案是使用像DVM的版本管理器。)

How do I uninstall Docker Toolbox?
You might decide that you do not need Toolbox now that you have Docker for Mac, and want to uninstall it. For details on how to perform a clean uninstall of Toolbox on the Mac, see How to uninstall Toolbox in the Toolbox Mac topics.
(你可能会认为你现在不需要Toolbox,你有Docker for Mac,并想要卸载它。 有关如何在Mac上执行干净卸载Toolbox的详细信息,请参阅如何在Toolbox Mac主题中卸载Toolbox。)

Docker for Mac
Gupao