我有一个用例,我偶尔想从我的主机复制一个文件到Vagrant客户机。
我不想这样做通过传统的供应(木偶/厨师),因为这往往是一次性的-我只是想快速添加到我的Vagrantfile。
我不想共享整个目录,可能是因为我想覆盖现有文件,而不破坏客户机上的整个目录。
当我想要做的只是复制一个文件时,编写一个shell配置脚本并处理潜在的转义似乎有点过分。
那么,将单个文件从主机复制到客户机的最简单方法是什么?
我有一个用例,我偶尔想从我的主机复制一个文件到Vagrant客户机。
我不想这样做通过传统的供应(木偶/厨师),因为这往往是一次性的-我只是想快速添加到我的Vagrantfile。
我不想共享整个目录,可能是因为我想覆盖现有文件,而不破坏客户机上的整个目录。
当我想要做的只是复制一个文件时,编写一个shell配置脚本并处理潜在的转义似乎有点过分。
那么,将单个文件从主机复制到客户机的最简单方法是什么?
当前回答
流浪者SCP插件工作,如果你知道你的流浪者盒子名称。 检查vagrant全局状态,它将提供您的盒子名称,然后您可以运行:
流浪的全球地位
id name provider state directory
------------------------------------------------------------------------
13e680d **default** virtualbox running /home/user
Vagrant SCP ~/foobar "name in my case default":/home/"user"/
其他回答
下面是我解决这个问题的方法:
步骤1 -找到私钥,ssh端口和IP:
root@vivi:/opt/boxes/jessie# vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /root/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
步骤2 -使用端口和私钥作为scp的参数传输文件:
scp -P 2222 -i /root/.vagrant.d/insecure_private_key \
someFileName.txt vagrant@127.0.0.1:~
我希望这对你们有帮助,
我最终做的是将文件保存在我的vagrant目录中(自动挂载为/vagrant/),并使用shell供应程序复制它:
command = "cp #{File.join('/vagrant/', path_within_repo)} #{remote_file}"
config.vm.provision :shell, :inline => command
您可以在~/.ssh/config中添加条目:
Host vagrant
User vagrant
HostName localhost
Port 2222
IdentityFile /home/user_name/.vagrant.d/insecure_private_key
和simplescp文件vagrant:/path/。可以使用vagrant ssh-config命令查找身份文件的路径。
如果你“cd ..”足够多的时间,你会发现vagrant文件夹,其中包含你所有的主机文件和文件夹
如果有人想将文件从windows主机传输到vagrant,那么这个解决方案对我来说是有效的。
1. Make sure to install **winscp** on your windows system
2. run **vagrant up** command
3. run **vagrant ssh-config** command and note down below details
4. Enter Hostname, Port, Username: vagrant, Password: vagrant in winscp and select **SCP**, file protocol
5. In most cases, hostname: 127.0.0.1, port: 2222, username: vagrant, password: vagrant.
您应该能够在您的流浪机器中看到目录。