Docker(5):virtual box和vagrant安装和基本使用

一、    下载软件

1.    Virtual box:VirtualBox 6.0.8 platform packages

2.    Vagrant:2.2.4

3.    docker官网
4.    vagrant cloud下载镜像网址

二、    创建虚拟机centos7步骤

1.    打开cmd

cd D:\Program Files\dockerimage
mkdir centos7
cd centos7


vagrant init centos/7


D:\Program Files\dockerimage\centos7>vagrant box add centos/7
==> box: Loading metadata for box 'centos/7'
    box: URL:
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 3
==> box: Adding box 'centos/7' (v1902.01) for provider: virtualbox
    box: Downloading:
==> box: Box download is resuming from prior download progress
    box: Download redirected to host: cloud.centos.orgining: --:--:--)
    box: Progress: 100% (Rate: 2877k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'centos/7' (v1902.01) for 'virtualbox'!

5.    启动本地环境(在virtual box中可以看到)

D:\Program Files\dockerimage\centos7>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1902.01' is up to date...
==> default: Setting the name of the VM: centos7_default_1560209749504_30254
==> 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:
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/d/Program Files/dockerimage/centos7/ => /vagrant

打开virtual box


vagrant ssh

D:\Program Files\dockerimage\centos7>vagrant ssh
vagrant@ Permission denied (publickey,gssapi-keyex,gssapi-with-mic).



vagrant box add 添加box的操作
vagrant init 初始化box的操作,会生成vagrant的配置文件Vagrantfile 
vagrant up 启动本地环境 
vagrant ssh 通过 ssh 登录本地环境所在虚拟机 (Windows不支持使用此指定登录)
vagrant halt 关闭本地环境 
vagrant suspend 暂停本地环境 
vagrant resume 恢复本地环境
vagrant reload 修改了 Vagrantfile 后,使之生效(相当于先 halt,再 up) 
vagrant destroy彻底移除本地环境 
vagrant box list 显示当前已经添加的box列表 
vagrant box remove 删除相应的box
vagrant package 打包命令,可以把当前的运行的虚拟机环境进行打包 
vagrant plugin 用于安装卸载插件
vagrant status 获取当前虚拟机的状态 
vagrant global-status 显示当前用户Vagrant的所有环境状态