Easiest way to copy a single file from host to Vagrant guest?

前端 未结 19 1776
暖寄归人
暖寄归人 2020-12-22 15:15

I have a use case where I occasionally want to copy a single file from my host machine to the Vagrant guest.

I don\'t want to do so via traditional provisioners (Pup

19条回答
  •  醉酒成梦
    2020-12-22 15:35

    Vagrant provides a way to execute a command over ssh instead of logging in, so for Linux host and guest you can use:

    • from host to guest:

    cat ~/file_on_host.txt | vagrant ssh -c 'cat - > ~/file_on_guest.txt'

    • from guest to host:

    vagrant ssh -c 'cat ~/file_on_guest.txt' > ~/file_on_host.txt

    No need for plugins or guest reloads. Just make sure to provide vagrant box ID to 'vagrant ssh' if you are not in the same dir as the Vagrantfile. Tested on Vagrant v1.8.1.

提交回复
热议问题