I have the following issue. I just configured Vagrant box on Windows 7. This is my first time to use Vagrant. Guest port 80, host 8008(8080 is in use). It's all working well but http://localhost:8008/ in Mozilla dosen't respond in any way. From the virtual mashine curl 'http://localhost:80' works as expected. From the local mashine curl -v "http://localhost:8008/"as expected too. I tryed different browsers and firewall off - notting. Restart win, restart browser, clear Mozilla cash - all the same. The server is Ubuntu.
This is the vagrantfile:
Vagrant.configure("2") do |config|
config.ssh.forward_agent = true
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.50.4"
config.vm.network "forwarded_port", guest: 80, host: 8008
config.vm.provision :shell, :path => File.join( "provision", "provision.sh")
end
I'm probably doing something wrong but I'm not sure what. Please for any suggestions what that may be.
you're using both private IP and forward port - use one or the other
Using forwarded port
Vagrant.configure("2") do |config|
config.ssh.forward_agent = true
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8008
config.vm.provision :shell, :path => File.join( "provision", "provision.sh")
end
and from your host you will be able to access http://localhost:8008/
using private IP
Vagrant.configure("2") do |config|
config.ssh.forward_agent = true
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.50.4"
config.vm.provision :shell, :path => File.join( "provision", "provision.sh")
end
and from your host you will be able to access http://192.168.50.4/
Related
I'm using a vagrant trusty64 box with nginx, flask, gunicorn and port forwarding is not working as expected
In the vagrant file, I have:
config.vm.network "forwarded_port", guest: 8090, host: 3100
config.vm.network "private_network", ip: "10.10.1.10"
On the box, I have run:
gunicorn myprj:app -b 10.10.1.10:8090
find nothing on host machine with http://10.10.1.10:3100
trying curl -v http://10.10.1.10:3100 gives the following output:
connect to 10.10.1.10 port 3100 failed: Connection refused
Reachable with guest port on host machine http://10.10.1.10:8090
I am new to the vagrant, did I miss/mess to Vagrant file.
Complete Vagrant file:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 8090, host: 3100
config.vm.network "private_network", ip: "10.10.1.10"
config.vm.synced_folder ".", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.name = "lopamudra_dev"
end
config.vm.provision "shell", inline: <<-SHELL
# Upgrading the environment
apt-get update
apt-get upgrade
# Installing nginx + uwsgi + flask
apt-get install -y python-pip python-dev nginx
pip install uwsgi flask gunicorn
SHELL
end
You are forwarding container 8090 to hostIP:3100 (localhost:3100)
At the same time you are creating a IP to access your container with 10.10.1.10 and you container has 8090 exposed, thats why you can acces it on 10.10.1.10:8090
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
config.vm.network "forwarded_port", guest: 8090, host: 3100
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "10.10.1.10"
I am currently setting up a development environment whereby there are two vagrant machines. The first hosts a website etc while the second hosts an API which the website calls. Currently my vagrantfiles are as follows:
API
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3001, host: 3001
end
Website
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
end
When i attempt to load the site which makes a call to the API I get:
Errno::ECONNREFUSED (Failed to open TCP connection to localhost:3001 (Connection refused - connect(2) for "localhost" port 3001)):
I understand there are multi-machine approaches but as I already have an seperate environment set up for each project I was wondering if there is any way for me to allow the connection between the two. I have looked into changing the hosts file on the vagrant machine hosting the site but not sure what I should do.
You need to put both VMs into the same private network and Website VM will be able to reach API VM via it:
config.vm.network "private_network", ip: "<ip_address>"
For example, for your case:
API VM:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3001, host: 3001
config.vm.network "private_network", ip: "192.168.200.3"
end
Website VM:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "private_network", ip: "192.168.200.2"
end
Now, Website VM can reach API VM on 192.168.200.3:3001. And of course you can reach Website VM on 127.0.0.1:3000 and API VM on 127.0.0.1:3001 from your host machine.
This question already has answers here:
Vagrant Synced Folder without reload?
(2 answers)
Closed 5 years ago.
I have primarily used Ubuntu boxes in Vagrant and in those any files created within the box have been successfully synced to Windows also. Usually things like git pull.
However, I now have centos/7 and cannot get any files to sync to Windows. If you create a file in /vagrant it never appears anywhere in Windows - not under C:\cygwin64\ nor C:\vm\machine. When I vagrant reload the box, all the files created inside the box are gone, except configuration files eg. /etc/httpd/conf/httpd.conf. Any changes in them are still present upon vagrant reload and also vagrant halt; vagrant up.
Here's the Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "forwarded_port", guest: 80, host: 8086, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 3306, host: 3386, host_ip: "127.0.0.1"
config.vm.synced_folder "./", "/vagrant"
# I have also tried the following:
# config.vm.synced_folder "C:/vm/machine", "/vagrant"
# config.vm.synced_folder "./", "/vagrant", type: "rsync", disabled: false
end
When doing vagrant up, both methods for synced_folder display this:
==> default: Rsyncing folder: /cygdrive/c/vm/machine/ => /vagrant
I have tried doing vagrant up from both cmd.exe and also from the Cygwin64 Terminal (under /c/vm/machine). Neither of them create files to the Windows directory, which is in C:\vm\machine.
What do I need to do to make files created in the box also sync to Windows?
When I try the same in an Ubuntu box, the file appears in Windows and does not disappear:
This is the Vagrantfile of the Ubuntu box:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "v0rtex/xenial64"
config.vm.network "forwarded_port", guest: 80, host: 8083, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 443, host: 8443, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 3306, host: 3303, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5003, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8000, host: 8003, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 9090, host: 9093, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 9091, host: 9193, host_ip: "127.0.0.1"
end
Upon vagrant up for the Ubuntu box, I see this:
==> default: Mounting shared folders...
default: /vagrant => C:/vm/ubu1604-64
The solution is as follows:
Change the Vagrantfile synced_folder part to this:
config.vm.synced_folder "./", "/vagrant", type: "virtualbox", disabled: false
And then run this command in the directory where the Vagrantfile is:
vagrant plugin install vagrant-vbguest
Then do either vagrant reload if it was already running, or vagrant up otherwise.
It will run for quite a while - for me it took about 7 minutes altogether. However, it is a one-time install, so all future vagrant up's will take a normal amount of time.
After that, the files created in the /vagrant directory will also appear in Windows C:\vm\machine (for example) and will persist between Vagrant sessions, ie. vagrant halt + vagrant up
I have the following vagrant VM:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 8000, host: 8080
config.vm.network "forwarded_port", guest: 8001, host: 8081
config.vm.synced_folder "../..", "/home/edgleweb"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4000"
vb.cpus = 2
end
config.vm.provision "shell", path: "./provisioner.sh", args: "edgleweb" #, run: "always"
end
I am having some issues with my VM which I use for development. I would like to spin another exact copy of it after a box update. I don't want to copy and paste the folder as that is against DRY principle. Vagrant documentation calls for a multi-machine setup as follows:
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "echo Hello"
config.vm.define "web" do |web|
web.vm.box = "apache"
end
config.vm.define "db" do |db|
db.vm.box = "mysql"
end
end
But I do want to keep my initial VM intact until I fully test the new one. I don't want to lose it. It is not apparent from the documentation how I keep it. How do I keep it?
You could use the vagrant snapshot command with either the save or push sub-commands to achieve this. See the documentation here.
I'm using Vagrant for multiple projects now with a per-project-installation, meaning I have multiple boxes. One for each project (or for production enviroment)
When I want to access my first Vagrantbox I access it via http://sitea.com:8080. My second Vagrantbox should listen to 1337 (I tried multiple ports here) but when I call http://siteb.com:1337 I'm getting an error in all browsers (ERR_CONNECTION_REFUSED in Chrome).
However, when I'm calling my second site like http://siteb.com it works without any problems. It seems that my second Vagrantbox just doesn't listen to the ports and uses the default port. But why is that?
First box (Which works with port only)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "puppetlabs/debian-7.8-64-puppet"
config.vm.provision :shell, path: "vagrant_ressources/bootstrap.sh"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.50.4"
config.vm.synced_folder ".", "/var/www", type: "nfs"
end
Second box (Which works without port only)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "puppetlabs/debian-7.8-64-puppet"
config.vm.provision :shell, path: "vagrant_ressources/bootstrap.sh"
config.vm.network :forwarded_port, guest: 80, host: 1337
config.vm.network "private_network", ip: "192.168.50.5"
config.vm.synced_folder ".", "/var/www", type: "nfs"
end
Both have the same vhost configuration, and my hosts file looks like this
# Vagrant
192.168.50.4 sitea.com
192.168.50.5 siteb.com
When using port forwarding with Vagrant you'll usually access localhost since the forwarded port is available at your host machine. Like this:
http://localhost:8080 -> should deliver the website siteA.com
http://localhost:1337 -> should deliver the website siteB.com
If you are able to access http://siteB[:80] it means that the DNS entry of siteB points to 192.168.50.5, which is the private network ip of that box.
Check:
getent hosts | grep siteB\.com
I bet it will give you 192.168.50.5.