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

前端 未结 19 1774
暖寄归人
暖寄归人 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:30

    If you are restrained from having the files in your directory, you can run this code in a script file from the Host machine.

    #!/bin/sh
    OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
    
    scp ${OPTIONS} /File/To/Copy vagrant@YourServer:/Where/To/Put/File
    

    In this setup, you only need to change /File/To/Copy to the file or files you want to copy and then /Where/To/Put/File is the location on the VM you wish to have the files copied to.

    If you create this file and call it copyToServer.sh you can then run the sh command to push those files.

    sh ./copyToServer.sh
    

    As a final note, you cannot run this code as a provisioner because that runs on the Guest server, while this code runs from the Host.

提交回复
热议问题