lbdbzj110 发表于 2015-4-15 09:27:07

在Win7下利用VirtualBox和Vagrant安装Docker

1.安装VirtualBox 和 Vagrant
  首先下载安装VirtualBox 和 Vagrant的windows版本,两个都安装完成后,假设Vagrant在D:\HashiCorp\Vagrant目录下。

1.1 下载
  cmd进入DOS,进入目录D:\HashiCorp\Vagrant\bin,一般标准命令是:
  To use the available boxes just replace {title} and {url} with the information in the table below.

$ vagrant box add {title} {url}$ vagrant init {title} $ vagrant up
  在线下载慢,可以到 http://www.vagrantbox.es/ 选择box文件,先下载下来。这里包括不同系统甚至是已经配置好环境直接可以用的box。
  因为我是为了要装Docker,所以尽量选64bit的,我选的这个https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box

1.2 拷贝
  下载完成后,是一个AMD64.box文件,拷贝到D:\HashiCorp\Vagrant\bin目录下。
  如图
  运行:
  vagrant box add base ubuntu-14.04-amd64-vbox.box
  base 表示指定默认的box,也可以为box指定名称,使用base时,之后可以直接使用 vagrant init 进行初始化,如果自行指定名称,则初始化的时候需要指定box的名称。


1.3 初始化
  设置好box之后,在当前工作目录运行:
  vagrant init

  这会生成Vagrantfile文件,如需要修改可编辑器打开,这里我们无需修改。

1.4 启动错误
  之前都挺正常,到了vagrant up的时候报错

  然后一直就不动了,给他指定vagarant up --provider virtualbox也不行,提示没装,后面看了下环境变量PATH里没有virtualbox的运行路径,添加了后重启成功了

1.5 启动成功

  如下图:


1.6 登陆
  我用putty登陆,账号密码默认都是vagrant,地址就用上面提示的127.0.0.1:2222
  


2.安装Docker
  Ubuntu安装好后,就可以在其中安装Docker,安装Docker有两种方法:

2.1 从官方的Ubuntu软件库来安装
  想安装docker,请使用下列命令:

sudo apt-get update    sudo apt-get install docker.io
  然后创建符号链接,以便在外壳上使用起来更容易。

sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
2.2 安装最新版Docker
  Docker更新很快,ubuntu源里的一般都跟不上,可以用这种方法安装新的
  1. 确认ls /usr/lib/apt/methods/https 是否存在,如果没有,下面安装:
  apt-get update
apt-get install apt-transport-https
  2. 将Docker仓储key加入apt 源列表:
  sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
  3.下面开始正式安装:
  $ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
  4.键入命令,如果没有curl,通过apt-get install curl首先安装
  $ curl -s https://get.docker.io/ubuntu/ | sudo sh
  5. 上述步骤完成后,检查是否存在/etc/init.d/docker 这个文件,如有表示安装完成,通过VirtualBox管理台,ps-ax可以看到docker正在运行。
  官方文档:
  If you'd like to try the latest version of Docker:
  First, check that your APT system can deal withhttpsURLs: the file/usr/lib/apt/methods/httpsshould exist. If it doesn't, you need to install the packageapt-transport-https.

[ -e /usr/lib/apt/methods/https ] || { apt-get update
apt-get install apt-transport-https }
  Then, add the Docker repository key to your local keychain.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
  Add the Docker repository to your apt sources list, update and install thelxc-dockerpackage.
  You may receive a warning that the package isn't trusted. Answer yes to continue installation.

$ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main\
> /etc/apt/sources.list.d/docker.list" $ sudo apt-get update
$ sudo apt-get install lxc-docker
  Note:
  There is also a simplecurlscript available to help with this process.

$ curl -sSL https://get.docker.io/ubuntu/ | sudo sh
  To verify that everything has worked as expected:

$ sudo docker run -i -t ubuntu /bin/bash
  Which should download theubuntuimage, and then startbashin a container.

3.运行Docker
  1. 为了确认docker安装正常,键入:
  sudo docker run -i -t ubuntu /bin/bash
  你会发现进入了docker,前面提示符不一样,键入exit退出。
  2.测试应用输出:
  sudo docker run ubuntu /bin/echo "Hello World"
  如果输出了Hello World,表示正常。
  此次,Docker中的在线演示都可以在本地实现了。
页: [1]
查看完整版本: 在Win7下利用VirtualBox和Vagrant安装Docker