Windows not viewing files that are made from linux - linux

I have vagrant up. Created a centosVM with it. I have shared folders activated so I can share files and folders between my local machine and VM. Problem is that it is one way. My VM and local machine (windows 7) can view the folders and files in the shared folder but if I create a file from the VM, it does not get displayed onto the shared folder in windows and whenever I restart the VM (by vagrant destroy or vagrant reload) then the files that I created from the VM, gets deleted. This is my vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.4.3"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if ENV["KONG_PATH"]
source = ENV["KONG_PATH"]
else
source = "./"
end
if ENV['KONG_VB_MEM']
memory = ENV["KONG_VB_MEM"]
else
memory = 2048
end
if ENV["KONG_VERSION"]
version = ENV["KONG_VERSION"]
else
version = "0.7.0"
end
config.vm.provider :virtualbox do |vb|
vb.name = "vagrant_kongDEBUG"
vb.memory = memory
end
config.vm.box = "centos/7"
config.vm.synced_folder ".", "/tmp", type: "rsync"
config.vm.network :forwarded_port, guest: 8000, host: 8000
config.vm.network :forwarded_port, guest: 8001, host: 8001
config.vm.network :forwarded_port, guest: 8443, host: 8443
config.vm.provision "shell", inline: "cd /tmp"
config.vm.provision "shell", inline: "ls -l"
config.vm.provision "shell", path: "provision.sh", :args => version
end

You're using rsync mechanism for your shared folder and it implies
The rsync synced folder does a one-time one-way sync from the machine
running to the machine being started by Vagrant.
You can force the refresh of a shared folder :
The rsync and rsync-auto commands can be used to force a resync and to
automatically resync when changes occur in the filesystem. Without
running these commands, Vagrant only syncs the folders on vagrant up
or vagrant reload.
so just run a vagrant rsync when you need to refresh the content of your shared folder or use the vagrant rsync-auto

Related

Can't SSH into Vagrant VM (without using vagrant ssh) part 2

This is a follow-up question to an earlier question. I've used the same Vagrantfile, but have commented out two lines I don't think are necessary.
I'm trying to ssh into my Vagrant box without using vagrant ssh. Below is my Vagrantfile and ssh configuration information:
Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 6144
v.cpus = 2
v.name = "mb_vagrant"
end
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.33.10"
config.ssh.forward_agent = true
# config.vm.provision :shell, path: "bootstrap.sh"
# config.vm.network :forwarded_port, host: 8001, guest: 8001
end
The output from vagrant ssh-config:
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile "/Users/mbigras/Google Drive/tmp/chef-repo/.vagrant/machines/default/virtualbox/private_key"
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
I've tried sshing into my machine with the following command:
$ ssh -i "/Users/mbigras/Google Drive/tmp/chef-repo/.vagrant/machines/default/virtualbox/private_key" -p 2222 vagrant#192.168.33.10
ssh: connect to host 192.168.33.10 port 2222: Connection refused
Also, as per the solution described in another answer, I've tried removing ~/.ssh/known_hosts before attempting to connect; however, it also doesn't work:
$ rm ~/.ssh/known_hosts
$ ssh -i "/Users/mbigras/Google Drive/tmp/chef-repo/.vagrant/machines/default/virtualbox/private_key" -p 2222 vagrant#192.168.33.10
ssh: connect to host 192.168.33.10 port 2222: Connection refused
What am I missing here?
Ssh service is bound to host machine's (i.e: 127.0.0.1) port 2222, but in the VM (guest machine) is still listening on port 22 (as the default port).
So, you should connect to port 22 on 192.168.33.10 or 2222 on 127.0.0.1. I.e:
$ ssh -i "<vagranfile-path>/.vagrant/machines/default/virtualbox/private_key" \
-p 22 vagrant#192.168.33.10
or
$ ssh -i "<vagranfile-path>/.vagrant/machines/default/virtualbox/private_key" \
-p 2222 vagrant#127.0.0.1
Also, it is not required to remove ~/.ssh/known_hosts file. Adding the following option will avoid host fingerprint check: -o UserKnownHostsFile=/dev/null
set the port forwarding section of vagrantfile like so:
# using a specific IP.
config.vm.network "private_network", ip: "192.168.56.101"
config.vm.network "forwarded_port", guest: 22, host: 2290
this will allow "normal" ssh into the the guest without go through vagrant ssh

How to forword firefox running in vagrant machine to local machine?

I am running django project openstack on virtual box. ./run_tests.sh --runserver 0.0.0.0:808. This is responsible to start django project. This is running inside virtual-box, which is created by Vagrant. I want to access this result into my firefox running on the same machine, outside of vagrant.
When I run firefox in virtaul box it gives
Error: no display specified
How I will do that, please check Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "centos7"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# 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.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
#config.vm.network "public_network", bridge: 'wlo1'
config.vm.network :"private_network", ip: "192.168.50.4"
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.network :forwarded_port, guest: 5000, host: 5000
config.vm.network :forwarded_port, guest: 8000, host: 8000
config.vm.network :forwarded_port, guest: 9000, host: 9000
config.vm.network :forwarded_port, guest: 9696, host: 9696
config.vm.network :forwarded_port, guest: 8774, host: 8774
config.vm.network :forwarded_port, guest: 35357, host: 35357
config.ssh.forward_x11 = true
config.ssh.insert_key = false
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = 3072
vb.cpus = 2
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
If you want to run graphical programs from your vm and forward to your host, its possible. I believe there are different ways but this is what I am using.
Install a X11 program on your host. On mac, you can install xquartz (http://xquartz.macosforge.org/landing/), on windows I am pretty sure there are equivalent but I am not familiar
configure your vm to do x forwarding, add the 2 parameters to your Vagrantfile
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
start vagrant and when you execute firefox it will forward to your host

Vagrant and Docker provider: a way to force proxy VM for Linux hosts?

TL&DR: Is there a way to force a proxy VM to be used by Vagrant, even if the host OS supports Docker natively?
I'm using Vagrant with Docker provider. The Vagrant VM is the OS and Docker containers host my apps (web servers, DBs).
Problem:
Linux containers do not run natively on non-Linux machines. If your
developers are on Mac or Windows, they can't run Docker containers
natively. Vagrant detects these cases and automatically spins up a
Linux virtual machine to run the Docker containers.
[...]
If Vagrant is being used with Docker on Linux, Vagrant won't
automatically spin up a virtual machine and instead will run Docker
natively
Source: http://www.vagrantup.com/blog/feature-preview-vagrant-1-6-docker-dev-environments.html
It's great that Vagrant automatically spin up a proxy VM for OS that doesn't support natively Docker, because they so have the same OS to work with.
But for Linux hosts, we're stuck with native Docker installation, which cause few problems:
file/folder permission
different user for different Linux OS (Apache user is sometime "apache", sometime "www", depending of your Linux distro)
Here is my Vagrant files for references:
DockerHost.Vagrantfile
Vagrant.configure("2") do |config|
config.vm.provision "docker"
config.vm.box = "ubuntu/trusty64"
config.vm.define "dockerhost"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder "/sites", "/sites" [...]
config.vm.provider :virtualbox do |vb|
vb.name = "Vagrant-Dockerhost"
vb.memory = 1024 # => Required by MySQL Server
end
end
Vagrantfile
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
DOCKER_HOST_NAME = "dockerhost"
DOCKER_HOST_VAGRANTFILE = "DockerHost.Vagrantfile"
Vagrant.configure("2") do |config|
config.vm.define "mysql-server" do |v|
v.vm.provider "docker" do |d|
d.image = "mysql"
d.name = "mysql-server"
d.env = {
MYSQL_ROOT_PASSWORD: "rootpasswd",
MYSQL_USER: "mysqluser",
MYSQL_PASSWORD: "userpasswd",
MYSQL_DATABASE: "dev"
}
d.volumes = ["/mysql:/var/lib/mysql"]
d.cmd = ["/entrypoint.sh", "mysqld"]
d.remains_running = true
d.vagrant_machine = "#{DOCKER_HOST_NAME}"
d.vagrant_vagrantfile = "#{DOCKER_HOST_VAGRANTFILE}"
end
end
config.vm.define "apache-server" do |v|
v.vm.provider "docker" do |d|
d.image = "lacavalerie/apache-server"
d.ports = ["80:80"]
d.name = "apache-server"
d.link("mysql-server:db")
d.volumes = [...]
d.cmd = ["/scripts/setup.rb"]
d.remains_running = true
d.vagrant_machine = "#{DOCKER_HOST_NAME}"
d.vagrant_vagrantfile = "#{DOCKER_HOST_VAGRANTFILE}"
end
end
end
Just use d.force_host_vm = true option
From Vagrant docs:
force_host_vm (boolean) - If true, then a host VM will be spun up even
if the computer running Vagrant supports Linux containers. This is
useful to enforce a consistent environment to run Docker. This value
defaults to "true" on Mac and Windows hosts and defaults to "false" on
Linux hosts. Mac/Windows users who choose to use a different Docker
provider or opt-in to the native Docker builds can explicitly set this
value to false to disable the behavior.

How To Run Vagrant Apache on Port 80 on Windows and OS X

Scenario
Two host machines, one Windows, one OS X, both running Vagrant and Virtualbox.
Problem
VirtualBox on Mac cannot bind to ports below 1024 without root access.
Don't know how to port forward port on Windows machine
Symptoms
Apache running perfectly on both machines
Mac can access site.local:8080 and use pfctl to access this on site.local
Windows machine can access site.local:8080 or site.local:80 (no port forwarding)
curl site.local on guest machine returns expected output
curl site.local on host machine returns connection refused
iptables on host machine dis
Port forwarding guest port 80 to host port 80 on Mac was working until today. Don't know how or why. Stopped for some reason.
Question
How can I force VirtualBox to run as root on port 80 (regarded as a bad idea)
Alternatively, how can I setup port forwarding on the Windows machine so that site.local:8080 is accessible at site.local?
Alternatively, how can I setup an OS-specific Vagrantfile that can be version controlled.
What I've tried
http://gielberkers.com/fixing-vagrant-port-forwarding-osx-yosemite/ - Works
Port forwarding on Windows 7 - Doesn't work
Enabling config.vm.network "public_network" and binding to en0 gives this error:
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
ARPCHECK=no /sbin/ifup eth1 2> /dev/null
Stdout from the command:
Determining IP information for eth1... failed.
Stderr from the command:
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = “devbox”
config.vm.provision :shell, path: "provision.sh"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# 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.
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 443, host: 443
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network "public_network"
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
#
# View the documentation for the provider you're using for more
# information on available options.
# Enable provisioning with CFEngine. CFEngine Community packages are
# automatically installed. For example, configure the host as a
# policy server and optionally a policy file to run:
#
# config.vm.provision "cfengine" do |cf|
# cf.am_policy_hub = true
# # cf.run_file = "motd.cf"
# end
#
# You can also configure and bootstrap a client to an existing
# policy server:
#
# config.vm.provision "cfengine" do |cf|
# cf.policy_server_address = "10.0.2.15"
# end
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file default.pp in the manifests_path directory.
#
# config.vm.provision "puppet" do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "default.pp"
# end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision "chef_solo" do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { mysql_password: "foo" }
# end
# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision "chef_client" do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# If you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
try to use following string in config file:
config.vm.network "forwarded_port", guest: 80, host: 80
https://docs.vagrantup.com/v2/networking/forwarded_ports.html
in additional you need to enable Public Network in the Vagrantfile
config.vm.network "public_network"
http://docs.vagrantup.com/v2/networking/public_network.html
If that doesnt help, may you please show your Vagrantfile?

Simple example of Vagrantfile / Dockerfile to run node app

I'm having difficulty trying to get a simple node app running inside a docker container hosted using vagrant.
This page explains the basic approach: https://www.vagrantup.com/blog/feature-preview-vagrant-1-6-docker-dev-environments.html
What I am unable to do is access the node app from my machine - in theory I believe I should be able to see my "hello world" style node/express app at localhost:8181...
Below is what I have so far:
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "docker" do |d|
d.build_dir = "."
d.ports = ["8080:5000"]
# Is this necessary if EXPOSE is used in Dockerfile?
d.expose = ["5000"]
d.remains_running = true
d.volumes = ["/shared"]
end
config.vm.network "forwarded_port", guest: 8080, host: 8181
config.vm.synced_folder "~/Documents/shared", "/shared"
end
Dockerfile:
# DOCKER-VERSION 0.8.0
FROM centos:6.4
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum install -y npm ImageMagick
ADD . /app
# Not necessary because node_modules are bundled
# RUN cd /app; npm install
EXPOSE 5000
CMD ["node", "/app/index.js"]
I've followed the documentation as closely as possible but just can't seem to achieve what I'm after. Any ideas?
Note: node app is working when running normally ie $ node index and accessed at localhost:5000
Thanks in advance
EDIT:
index.js:
var express = require('express'),
http = require('http');
var app = express();
var port = 5000;
app.get('/', function(req, res) {
res.send('Hello World');
});
var server = http.createServer(app);
server.on('listening', function() {
console.log('Express server listening on port ' + port);
});
server.listen(port, '0.0.0.0');
setInterval(function(){
console.log('running');
}, 5000);
package.json:
{
"name": "vagrant-docker-node",
"version": "0.0.0",
"dependencies": {
"express": "^4.1.0"
},
"main": "index.js"
}
I actually ran into the same issue. Not sure if it's intended behavior or bug but setting forwarded_port in a Vagrantfile with a Docker provider does nothing on the host boot2docker machine.
Unless I'm missing something, you have to either provide your own host machine with another Vagrantfile opening the correct ports or modify the one provided by Vagrant.
Approach 1: Provide your own host machine (based on boot2docker)
Here's the base Vagrantfile for the boot2docker host: boot2docker Vagrantfile. You need to edit a copy of this Vagrantfile and set your forwarded ports here.
Then, in your Docker app Vagrantfile, modify as follow:
config.vm.provider "docker" do |d|
# Specify here the path to the updated host Vagrantfile
d.vagrant_vagrantfile = "../boot2docker/Vagrantfile"
... # edited out for clarity
end
Make sure you point to your updated host machine. Here I set it to an upper level shared directory because if you want to share this machine between multiple Docker apps with seperate Vagrantfiles, you'll have to point to the same host Vagrantfile (otherwise it'll try to spin up new host VMs).
Approach 2: Update Vagrant's host machine
You can also update the Vagrantfile automatically used by Vagrant which is located in %VAGRANT_HOME%/data/docker-host/Vagrantfile. Modify the file to open your ports.
Then do a vagrant global-status to get the ID of the host machine and vagrant reload machineId to restart the machine which will trigger the port re-open and update.
I'm not sure if there's a better or sanctionned way to do this but that's the only way I could have the ports forwarded all the way from Docker container to physical machine.
Shouldn't you forward the exposed port 5000 from Docker to your host, using Vagrant?
config.vm.network "forwarded_port", guest: 5000, host: 8181
(to get your app reachable on port 8181 from your host browser, for example)
Instead of:
config.vm.network "forwarded_port", guest: 8080, host: 8181
Flows/redirects summary:
Docker container Vagrant VM Your computer
:8080 => :5000 => :8181
What's your host OS (the one you execute the "vagrant" command on)? If it's non-Linux (e.g. OSX or Windows) then your Docker container will be riding on top of a Linux VM (usually TinyCore Linux inside VirtualBox), and the port forwarding will be done from inside that VirtualBox into the Docker container.
You should see evidence of port forwarding taking effect by looking for listening TCP sockets using "netstat -tlpn" (on Linux) or "netstat -an" (on OSX)

Resources