vagrant 设置文件映射,将windows文件夹映射到linux中

首先需要注意的是:
vagrant虚拟的linux的文件是无法映射到windows中的,只能windows的文件映射到linux中,就像window环境中的某个文件夹挂载到vagrant 的 linux中的感觉,但是不能把linux的文件夹挂载到windows,具体操作如下:

打开Vagrantfile,修改配置内容如下(完全修改):

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "centos-6.6-x86_64"
  
  config.vm.hostname = "dev"
  config.ssh.username = "root"
  config.ssh.password = "123456"
  config.ssh.insert_key = "true"
  config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
  config.ssh.forward_agent = true
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
   config.vm.network "forwarded_port", guest: 80, host: 80

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.10.12"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"
    config.vm.synced_folder "D:\\linux\\fecshop", "/www/web/develop/fecshop"
  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    # vb.gui = true
    vb.name = "dev"
    # Customize the amount of memory on the VM:
    vb.memory = "2048"
  end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

在上面的配置中可以看到如下:

config.vm.synced_folder “D:\\linux\\fecshop”, “/www/web/develop/fecshop”

第一个路径是window的路径,第二个是vagrant’中linux的路径

启动,如图:

 

注意:

1.如果 /www/web/develop/fecshop 这个文件夹在linux中存在,那么启动后,原来的文件夹将看不到。

2. 如果linux存在文件夹/www/web/develop/fecshop,您想把这个文件夹的内容复制到映射后的/www/web/develop/fecshop中,那么,您可以先将/www/web/develop/fecshop  改名为 /www/web/develop/fecshop_cp,然后,添加映射配置,重启(vagrant reload)vagrant,然后通过命令复制过去即可

\cp -rf /www/web/develop/fecshop_cp/*  /www/web/develop/fecshop/

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注