新手玩Docker

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

环境

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

  • docker
  • boot2docker
  • VirtualBox

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

新手玩Docker_第1张图片

启动Docker

boot2docker init创建Docker虚拟机

我们打开VirtualBox:

新手玩Docker_第2张图片

左边栏是空的,好了,现在我们使用boot2docker来创建docker客户端所需的虚拟机,看动画:
新手玩Docker_第3张图片
启动完成后就是这么一个鬼
新手玩Docker_第4张图片

我们动画中演示的是从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/

你可能感兴趣的:(新手玩Docker)