如何从本地安装Vagrant VM

时间:2015-08-22 03:59:47

标签: vagrant virtualbox vagrantfile vagrant-windows

我正在学习Udacity课程,他们让我安装Vagrant。但由于.box文件的大小,我首先将其从其他网络下载到本地,然后我得到了这个tar文件trusty-server-cloudimg-i386-vagrant-disk1.tar。他们让我下载他们的文件夹fullstack。该文件夹包含以下结构:

|--fullstack
    |--vagrant
        |--.vagrant
        |--catalog
        |--forum
            |--forum.py
            |--forum.sql
            |--forumdb.py
        |--tournament
            |--tournament.py
            |--tournament.sql
            |--tournament_test.py
        |--pg_config
        |--Vagrantfile

Vagrant你可以从this link看到他们的表现。现在当我在vagrant up上使用git bash时,前往fullstack/vagrant位置代码即将开始:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty32' could not be found. Attempting to find and in
stall...
    default: Box Provider: virtualbox
    defa

ult: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/trusty32'
    default: URL: https://atlas.hashicorp.com/ubuntu/trusty32
==> default: Adding box 'ubuntu/trusty32' (v20150818.0.0) for provider: virtualb
ox

现在您可以在代码中向下看到它正在尝试从我在本地下载的在线下载.box文件,我在我的驱动器上有。我想编辑一些配置文件,这样当我使用vagrant up时,它应该使用本地文件trusty-server-cloudimg-i386-vagrant-disk1.tar文件来安装,不应该去下载在线文件

default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty32/versions/20150818.0.0/providers/virtualbox.box
    ==> default: Box download is resuming from prior download progress
        default: Progress: 0% (Rate: 13410/s, Estimated time remaining: 5:35:56))

如果还需要一些信息,请在评论中提问我,我会更新我的问题。

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.provision "shell", path: "pg_config.sh"
  # config.vm.box = "hashicorp/precise32"
  config.vm.box = "ubuntu/trusty32"
  config.vm.network "forwarded_port", guest: 8000, host: 8000
  config.vm.network "forwarded_port", guest: 8080, host: 8080
  config.vm.network "forwarded_port", guest: 5000, host: 5000
end

pg_config.sh:

apt-get -qqy update
apt-get -qqy install postgresql python-psycopg2
apt-get -qqy install python-flask python-sqlalchemy
apt-get -qqy install python-pip
pip install bleach
pip install oauth2client
pip install requests
pip install httplib2
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'

vagrantTip="[35m[1mThe shared directory is located at /vagrant\nTo access your shared files: cd /vagrant(B[m"
echo -e $vagrantTip > /etc/motd

当我尝试添加这样的内容时,我收到以下错误:

$ vagrant box add mybox C:\Users\Rahul\Downloads\trusty-server-cloudimg-i386-va
grant-disk1.tar
c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/generic.rb:214:in `initialize':
 the scheme file does not accept registry part: C:UsersRahulDownloadstrusty-serv
er-cloudimg-i386-vagrant-disk1.tar (or bad hostname?) (URI::InvalidURIError)
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:218:in `
new'
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:218:in `
parse'
        from c:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/uri/common.rb:747:in `
parse'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:465:in `metadata_url?'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:77:in `block in call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:75:in `map'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builtin/box_add.rb:75:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/warden.rb:34:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/builder.rb:116:in `call'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:66:in `block in run'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/u
til/busy.rb:19:in `busy'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:66:in `run'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/comma
nds/box/command/add.rb:89:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/comma
nds/box/command/root.rb:61:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
li.rb:42:in `execute'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:301:in `cli'
        from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:1
74:in `<main>'

已编辑添加了一些错误:

$ vagrant box add mybox C:/Udacity/trusty-server-cloudimg-i386-vagrant-disk1.ta
r
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'mybox' (v0) for provider:
    box: Unpacking necessary files from: file://C:/Udacity/trusty-server-cloudim
g-i386-vagrant-disk1.tar
    box:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Couldn't open file /Udacity/trusty-server-cloudimg-i386-vagrant-disk1.tar

1 个答案:

答案 0 :(得分:5)

您可能需要添加如下框。请参阅http://docs.vagrantup.com/v2/cli/box.html

vagrant box add yourbox file:///box-file-location/yourbox.box
vagrant init yourbox
vagrant up