Docker Toolbox in Action

Docker Toolbox 可以很方便的在 Windows / Mac 上安装使用 Docker,原理就是通过 Virtualbox 安装一台新的 Linux 虚拟机,然后在虚拟机上运行 Docker Engine,同时,在 Win / Mac 上可以直接操作 Docker。

Docker Toolbox 中包含了:

建议用 Toolbox 自带的,不要再各自独立安装。

  • Docker Engine
  • Compose
  • Machine
  • Kitematic

Docker Toolbox 还带了 Docker Quickstart Terminal 用于启动带 Docker 脚本的 Terminal。

Mac Install

Mac 上通过 brew-cask 可以很方便的进行 Docker Toolbox 的安装。

1
2
$ brew install brew-cask
$ brew cask install dockertoolbox

操作

通过 Kitematic / Docker Quickstart Terminal 可以启动 Docker VM,进入 Docker CLI 后即可正常操作。

1. 创建主机

第一次进入时,会创建一个台新主机,其中包括以下步骤:

  • 创建新的证书
  • 下载 boot2docker.iso(Lightweight Linux for Docker)然后 Virtualbox 用该 iso 作为引导盘,创建 Docker VM。
  • 启动 Docker VM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$ bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
Creating CA: /Users/lanvige/.docker/machine/certs/ca.pem
Creating client certificate: /Users/lanvige/.docker/machine/certs/cert.pem
Running pre-create checks...
(default) Image cache directory does not exist, creating it at /Users/lanvige/.docker/machine/cache...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v1.9.1
(default)
(default) Boot2Docker v1.9.1 has a known issue with AUFS.
(default) See here for more details: https://github.com/docker/docker/issues/18180
(default) Consider specifying another storage driver (e.g. 'overlay') using '--engine-storage-driver' instead.
(default)
(default) Downloading /Users/lanvige/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v1.9.1/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect Docker to this machine, run: /usr/local/bin/docker-machine env default
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

2. 进入主机

可以通过 docker-machine env 查看 Docker 主机的配置信息:

1
2
3
4
5
6
7
8
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/lanvige/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)

通过 docker-machine ssh 进入 Docker 主机:

1
$ docker-machine ssh default

3. 操作

这时,无论是在 Win / Mac 还是在 Docker VM 中,通过 Docker Quickstart Terminal 进入 Terminal 就可以正常的使用 Docker 命令了。

1
2
$ docker -v
Docker version 1.9.1, build a34a1d5

下载 Rails 镜像

1
$ docker pull rails:4.2.5

Issues:

1. Volume

Docker Toolbox 中的 Volume 映射的目录不是 Win / Mac 机上的目录,而是 Docker VM 上的目录,这一点一定要注意。

REF::