How to copy file from local vagrant to local system?

北战南征 提交于 2021-01-29 08:00:19

问题


I want to copy local.conf from local vagrant machine to local system(my machine). Vagrant is running on the same machine. I tried the following command. It run successfully, but when I search local.conf file on my system I get nothing.

[vagrant@localhost devstack]$ scp vagrant@192.168.50.4:/home/vagrant/local.conf local.conf 
vagrant@192.168.50.4's password: 
local.conf                                              100% 3857     3.8KB/s   00:00    
[vagrant@localhost devstack]$ 

回答1:


To copy files from host to vm (and vice versa) you do not necessarily need specific protocol like scope or ftp.

By default vagrant automatically makes a /vagrant directory a shared folder with your local folder. so you can just copy any files from the vm into the /vagrant directory and you will see them under your local folder where you have the Vagrantfile and where you initialized vagrant.

And if you have other files located on your local hard drive that you want to share with your vm, you can easily add a shared folder from the Vagrantfile

  config.vm.synced_folder "/Users/fhenri/myproject", "/project"

will shared the local folder /Users/fhenri/myproject with the /project folder from the vm and you can just use mv or cp to move / copy files from one to another




回答2:


You need to specify on which machine you run your command. Your command is basically correct, but you need to run it on your local host, not on vagrant machine. In example, you can think of two hosts, local and vagrant:

[local]$ scp vagrant@vagrant:/home/vagrant/local.conf local.conf 
vagrant@vagrant's password: 
local.conf                                      100% 3857     3.8KB/s   00:00    

Trying ls in the same directory should show you your required file:

[local]$ ls local.conf



回答3:


for example:

"sudo scp -P 2222 vagrant@127.0.0.1:/home/vagrant/dumpfilename.sql /home/ "



来源:https://stackoverflow.com/questions/32315256/how-to-copy-file-from-local-vagrant-to-local-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!