参考资料chenhengjie123 ,感谢@chenhengjie123分享

环境

实验所用的是 os x 系统,所以需要通过 boot2docker 来引导,然后需要 VirtualBox VM 启动 docker,所以可想而知我们的环境需要 3 个组件:

docker 和 boot2docker 可以通过命令行安装,也可以通过安装包安装,但是别忘了 VirtualBox VM 的安装哦,安装后就是小面的小图标:

这里写图片描述

启动 Docker

boot2docker init创建 Docker 虚拟机

我们打开 VirtualBox:

这里写图片描述

左边栏是空的,好了,现在我们使用 boot2docker 来创建 docker 客户端所需的虚拟机,看动画:
这里写图片描述
启动完成后就是这么一个鬼
这里写图片描述

我们动画中演示的是从 VirturalBox 中双击启动 Docker 客户端,也可以在外部通过boot2docker start 启动.这样启动后,完全是看不到 VirturalBox 里的内容也看不到海豚的图像.

Hello World

要想在外部连接 Docker 客户端,需要先设置环境变量,通过下面命令执行:

eval '$(boot2docker shellinit)'

跑个官方提供的 hello-world 镜像:

docker run <镜像名>

localhost:~ wuxian$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
a8219747be10: Pull complete
91c95931e552: Already exists
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd18681cf5daeb82aab55838d
Status: Downloaded newer image for hello-world:latest
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

For more examples and ideas, visit:
http://docs.docker.com/userguide/



↙↙↙阅读原文可查看相关链接,并与作者交流