首页 > 代码库 > vagrant 基本命令讲解

vagrant 基本命令讲解

https://www.vagrantup.com/,  下载对应系统的软件

安装完毕vagrant

打开命令行, 输入vagrant --help  或者 vagrant -h 查看帮助文档


$ vagrant
Usage: vagrant [options] <command> [<args>]

    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.

# ...


  1.  vagrant -v 查询版本

    D:\vagrant\mariadb>vagrant --v
    Vagrant 1.9.4


  2. vagrant box  list, 列出已安装的box

    base (virtualbox, 0)


  3. vagrant add box   xxx添加box

    xxx可以是在线共享出来的box名称, 如 https://atlas.hashicorp.com/boxes/search

    里面的ubuntu/trusty64hashicorp/precise64

    xxx可以是一个本地的box名称,   如vagrant add box  base  centos6.5.box

    xxx可以是一个网络地址, vagrant box add https://atlas.hashicorp.com/ubuntu/boxes/trusty64



  4. vagrant init hashicorp/precise64初始化virtualbox

    hashicorp/precise64就是box名称, 可以是自己名称的box


  5. vagrant up 启动虚拟机

    Bringing machine ‘default‘ up with ‘virtualbox‘ provider...
    ==> default: Importing base box ‘base‘...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Setting the name of the VM: mariadb_default_1494900190484_18488
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
    ==> default: Forwarding ports...
        default: 22 (guest) => 2222 (host) (adapter 1)
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2222


  6. vagrant ssh 链接虚拟机,   默认账号密码 vagrant

  7. vagrant halt 关闭虚拟机

  8. vagrant destroy  销毁虚拟机


技术分享







本文出自 “四叶草” 博客,请务必保留此出处http://3427585.blog.51cto.com/3417585/1926143

vagrant 基本命令讲解