Docker:Window上的Boot2Docker安装和入门

最近在研究Devops,目前最热门的Docker先研究下,由于公司虚拟机申请IP麻烦,先在工作机器上安装一个Windows版本的。
Docker虽然是Linux内核,但是官方还是支持了Windows和OS X。
Boot2Docker官方下载地址:https://github.com/boot2docker/windows-installer/releases
Boot2Docker官方安装手顺:http://docs.docker.com/installation/windows/
目前最新发布版本是1.5.0。安装包内包含了Docker、VisualBox、Git,总共才128m,果然很小很轻量。

安装完了之后桌面会出现【Boot2Docker Start】图标,也就是传说中的docker客户端,双击之后幽幽自动关闭了,说好的创建虚拟机呢?打开CMD查看状态,出现以下错误:

boot2docker status

error in run: Failed to start machine “boot2docker-vm”: exit status 1

原因:机器未支持虚拟化,重启到BIOS将虚拟化enable。
线索:看用户目录下日志文件:.VirtualBox\VBoxSVC.log

重启后再继续,打开客户端【Boot2Docker Start】,这次顺利启动,在CMD中查看虚拟机状态,

boot2docker status

running

显示正在运行,然后让我们初步了解一下。

1.Dcoker默认用户

docker@boot2docker:~$ whoami

docker

可以使用PUTTY连接该虚拟机boot2docker-vm,具体操作方式在下一章【Boot2Docker文件系统】中详细说明。

2.第一个image:hello world
按照安装手顺先看看能不能把第一个应用运行起来。

docker@boot2docker:~$ docker run hello-world

Unable to find image ‘hello-world1:latest’ locally Pulling repository hello-world1 FATA[0000]
Get https://index.docker.io/v1/repositories/library/hello-world1/imag es: dial tcp: lookup index.docker.io: no such host

公司内貌似连接不上Docker Hub,需要设置代理,设置方法和普通linux操作没什么不同。

sudo vi /var/lib/boot2docker/profile

在新建的profile文件中填入公司代理:

export HTTP_PROXY=http://proxy.host:port
export HTTPS_PROXY=https://proxy.host:port

保存后重启docker服务:

sudo /etc/init.d/docker restart

也可以在CMD中重启:

boot2docker stop
boot2docker start
Waiting for VM and Docker daemon to start……………………….ooooooooooo Started.
Trying to get Docker socket one more time Error requestingsocket: exec: “ssh”: executable file not found in %PATH%
Docker client does not run on Windows for now. Please use “boot2docker” ssh to SSH into the VM instead.

但是可能由于没有配置PATH,在CMD中重启后还是要回到客户端中去,有点麻烦,不推荐。
然后在重新试一下:

docker@boot2docker:~$ docker run hello-world
Unable to find image ‘hello-world:latest’ locally
511136ea3c5a: Pull complete
31cbccb51277: Pull complete
e45a5af57b00: Pull complete
hello-world:latest: The image you are pulling has been verified.
Important: imag everification is a tech preview feature and should not be relied on to provide security.

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/

通过这个过程,我们以下几点认识:
①在Windows中运行的docker,必须依赖VirtualBox的虚拟机为平台,docker的轻量级实际没怎么体现出来。作为一个VM小更多的container,还没发现有什么优势,期待后面在Ubantu中的实验结果;
②除了docker自带的几个命令以外,其他一切操作和Linux没什么区别,docker在虚拟机中也是作为一个service存在,下一章接触一下container、log等文件系统;
③运行Image时,的确先从本地查找,本地没有时会去Docker Hub上下载同名image。

你可能感兴趣的:(Docker)