Vagrant. Copy file from guest (darwin, OSX) to host (darwin, OSX) - vagrant

How can one copy files from guest to host in Vagrant environment?
I know there are synced_folders but this doesn't work with darwin guest.
I need to copy build result from guest to host, ideally using vagrant provisioning scripts as all my other stuff happens there.
VM is VirtualBox.

From your host use this command -
scp -P <vagrant guest ssh port number> vagrant#localhost:/path/to/source/file /path/to/destination/file
The "vagrant guest ssh port number" is the forwarded port from host to guest for ssh, and you can find this from the output of your vagrant up command.

Related

Homestead with HyperV unable to create SMB folders - mount error(2): No such file or directory

After running vagrant up I get the following error message.
Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
==> homestead: Setting hostname...
==> homestead: Mounting SMB shared folders...
homestead: C:/Code => /home/*****/code
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t cifs -o vers=3.02,credentials=/etc/smb_creds_vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727,uid=1000,gid=1000,mfsymlinks,_netdev,nofail //169.254.x.x/vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727 /home/*****/code
The error output from the last command was:
mount error(2): No such file or directory
I am able to ssh into the HyperV instance and when I run the command it returns the same. If I look at the properties of C:/Code folder I can see the network path is \\PCNAME\vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727 so the same as the mount command other than the PCNAME is now an IP. I can ping the IP from within the instance and seems to work ok.
Homestead file:
folders:
- map: C:/Code
to: /home/vagrant/code
type: smb
smb_username: vagrant
smb_password: vagrant
The vagrant user has full permissions to the local code folder.
I am running Windows 11, Vagrant 2.3.1, HyperV 10. The External Switch is set-up via my Wi-Fi - could that cause an issue?

copy file from host to vagrant virtual machine

I am new with virtual machine. I want to copy a file from host (Mac) to vagrant virtual machine. I could not share a folder, so I want to use command line. How can I copy a file from host to vagrant virtual machine with command line?
To copy a file from the host to vagrant:
scp -P 2222 /path/to/file vagrant#127.0.0.1:.
By default The vagrant instance uses port 2222 and ip 127.0.0.1. The password for vagrant is 'vagrant'.
The file will be copied to the home of vagrant.
To copy a file from vagrant to host machine:
scp -P 2222 vagrant#127.0.0.1:/path/to/file
one easy way is to let vagrant handles the copy through the File Provisioner :
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
If you really want to use a command line, it might be dependant on your VM, assuming you have linux based VM, you could use scp and copy the file through ssh. see https://unix.stackexchange.com/a/106482
There is an officially supported command vagrant upload:
vagrant upload source [destination] [name|id]

Update VM's bridged MAC address with Vagrant

Is it possible to dynamically change the MAC address of a VM, using Vagrant?
My host is MacOsX, my guest is Debian8,
and I want to test the following commands (learning about network):
/etc/init.d/networking stop
ifconfig eth0 down
ifconfig eth0 hw ether aa:aa:aa:aa:aa:aa
ifconfig eth0 up
dhclient eth0
The problem is that the first command (/etc/init.d/networking stop) freezes the ssh terminal, so I can't really go forward (I have to vagrant halt, and up again).
And if I remove the first command, then the networking system automatically assigns an IP address to the VM machine as soon as "ifconfig eth0 up" is executed, which defeats the purpose of testing the "dhclient eth0" command (which is actually the one I would like to test).
I'm aware that one can statically change the MAC address at startup (with config.vm.network "public_network" , :mac => "5CA1AB1E0001" for instance), but that's not what I want to do here.
So is dynamic update of the MAC address in a public network with Vagrant possible at all?
You cannot run this command from vagrant ssh as vagrant will use the NAT (eth0) interface to ssh into the VM so if you shut it down the interface, you're cutting your ssh connection.
If you want to run this command you will need to login to the VM directly from VirtualBox (or VMWare if you use this provider) and you will be able to run this command

How to Ssh into docker container that is running inside Vagrant?

I am running a Vagrant VM under Windows 7 . The Vagrant VM is running a docker container. So the configuration is :
Windows7[Vagrant[Docker]]
I want to ssh from Windows into the Docker container.
The docker container is running sshd and I can successfully ssh from Vagrant VM to Docker container.
sudo docker ps
gives:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64b13daab5f2 ubuntu:12.04 "/bin/bash" 14 minutes ago Up 14 minutes 0.0.0.0:49153->22/tcp thirsty_morse
From the Vagrant VM:
ssh root#localhost -p 49153
works just fine. So Vagrant VM's port 49153 is forwarded to Docker container's port 22.
I've added
config.vm.network "forwarded_port", guest:49153, host:49155
to Vagrantfile so that localhost:49155 on Windows is forwarded to Vagrant VM:49153
This is where things break down. When I try to ssh from Windows to localhost:49155, I get:
ssh: connect to host localhost port 49155: Connection refused
So Windows:49155 -> Vagrant:49153 is not working. I thought that it may be a problem related to listening on a port on Vagrant VM's external ip so I've installed rinetd into Vagrant VM and I've done:
bindadress bindport connectaddress connectport
0.0.0.0 49153 127.0.0.1 49153
Still no luck. What am I missing here?
Ok, answering my own question. It works now. I think the most likely reason for the problem was that port 49153/55 and its neighbours is actually used by some windows services by default. I changed to mapping for ports in the Vagrant file to use 9090 for Windows and everything worked. No need to rinetd either. I've also done:
sudo docker run -v /vagrant:/opt/data -p 0.0.0.0:49153:22 -i -t ubuntu:12.04
Notice the 0.0.0.0: it may or may not be relevant but this configuration is working for me.

How do I access the host from the guest in vagrant?

I have a Ubuntu 14.10 64-bit box running in vagrant on a Windows 8.1 64-bit host.
In this book it is said that if I set a host-only network, I should be able to access the host with the same ip address as the guest if I change the last octet to 1:
config.vm.network "hostonly", "192.168.33.10"
In the latest vagrant, hostonly is not available any more, so I tried setting it to private_network.
However, I am not able to ping 192.138.33.1 from my guest.
How do I access the host from the guest when using vagrant?
Ping doesn't work. You can connect your host server by this way
ssh user#192.138.33.1
If your host server has ssh service enabled.

Resources