Vagrant and Docker nfs failed: Bad file descriptor - macos

After a lot of review trying to use rsync in Vagrant with Docker as provider. (bidirectional sync)
I moved on to use nfs to sync my files inside the VM boot2docker
I have this vagrant error message after vagrant up
dockerhost: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'vers=3,udp' 192.168.50.1:'/Users/myMac/workspace/docker-vagrant/test' /project
Stdout from the command:
Stderr from the command:
mount: RPC: Unable to receive; errno = No route to host
mount: mounting 192.168.50.1:/Users/myMac/workspace/docker-vagrant/test on /project failed: Bad file descriptor
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "dduportal/boot2docker"
config.vm.define "dockerhost"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.network "private_network", ip: "192.168.50.4"
config.vm.synced_folder "../", "/project", type: "nfs"
...
My mac already have nfs because started up the service using nfsd start
In the Vagrant documentation recommend to use rsync but I didn't find a way to rsync from VM to my MAC and vice versa.
I'm using
Mac Yosemite
Vagrant 1.8.1
VM dduportal/boot2docker

I posted my question directly on the dduportal/boot2docker project.
and this is the correct configuration if you have your custom Docker Host in different directory.
config.vm.synced_folder "../", "/vagrant", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync"
Reference:
https://github.com/dduportal/boot2docker-vagrant-box/issues/48

Related

Vagrantbox with Hyper-V not starting

I'm trying to setup a vagrantbox with Hyper-V on my local windows-10 mashine. My Workstation is running behind a proxy, but I configured a local cntlm proxy to get around these limitations. Proxy settings work fine since I was able to install a vagrant plugin and downloan a box image.
But now my guest linux does not start up and I am running out of ideas.
My vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04" # ubuntu 18.04 image with support for virtual box and Hyper-V
config.vm.hostname = "skywalker"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provider "hyperv" do |hv|
hv.memory = "2048"
end
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # prevent tty errors
# install the vagrant plugin "vagrant-cachier" to cache downloaded artifacts
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
# vagrant behing local cntlm proxy if plugin exists (= provinzial win10 workstation)
if !Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://localhost:3128/"
config.proxy.https = "http://localhost:3128/"
config.proxy.no_proxy = "localhost, 127.0.0.1"
end
# --------------------------------------------------------------------------
# provision virtual mashine (basic setup) and install applications in VM
#config.vm.provision "shell", path: "scripts/install-ansible.sh"
config.vm.provision "shell", path: "scripts/install-ncdu.sh"
config.vm.provision "shell", path: "scripts/install-git.sh"
config.vm.provision "shell", path: "scripts/install-openjdk-11.sh"
config.vm.provision "shell", path: "scripts/install-maven.sh"
config.vm.provision "shell", path: "scripts/install-node-npm.sh"
config.vm.provision "shell", path: "scripts/install-docker.sh"
config.vm.provision "shell", path: "scripts/install-docker-compose.sh"
# npm webserver
config.vm.provision "shell", path: "apps/install-npm-apps.sh"
config.vm.network "forwarded_port", guest: 8000, host: 8000
# artifactory setup (start artifactory after vm startup)
config.vm.network "forwarded_port", guest: 8081, host: 8081 # artifactory from docker
config.vm.network "forwarded_port", guest: 8082, host: 8082 # artifactory from docker
# See README.md for Artifactory in Docker
end
Starting the box with this settings results in
C:\home\work\workspace\vagrant-boxes\skywalker (master -> origin)
λ vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: fe80::215:5dff:fe02:8b01
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: fe80::215:5dff:fe02:8b01:22
default: SSH username: vagrant
default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
On a different mashine with VirtualBox as VM provider this Vagrantfile works fine. Sadly I cannot use any VM provider other than Hyper-V on my windows mashine due to limitations which are out of my control ...
I set up Hyper-V using Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All.
Any ideas? Thanks in advance and best regards. Sebastian
I went through this exercise last week and saw similar problems. I made lot of progress following these steps and the vm's get spun up at a reasonable time under windows 10 hyper-v. This is what i did.
Followed this blog and tried creating a vm successfully first.
https://win32.io/posts/Vagrant-Install-HyperV
Then i created a simple vagrantfile and got it to work successfully. Here is mine ,
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.hostname = 'utility-server-1'
config.vm.network 'public_network', bridge: 'Internet'
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "hyperv" do |vb|
vb.memory = "4024"
vb.cpus = 2
vb.vmname = 'utility-server-1'
end
end
Once this works, add more complex steps from your vagrantfile, like shell scripts and forwarded ports.

Vagrant Vagrantfile config

I have this vagranfile for box "centos/7"
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant"
config.vm.provision "shell", path: "./conf/bitrix-env.sh"
config.vm.boot_timeout = 100
config.vm.provider :virtualbox do |vb|
vb.gui = true
vb.memory = "1024"
end
end
vagrant up - command works clear, but scripts in provision don't install
after i tried to start vagrant provision, but had an error:
SSH is getting permission denied errors when attempting to connect
to the IP for SSH. This is usually caused by network rules and not being
able to connect to the specified IP. Please try changing the IP on
which the guest machine binds to for SSH.
How can i fix this and install all provisions?
The problem is due to the below line in your vagrantfile
config.vm.synced_folder '.', '/home/vagrant'
The authorized_keys file for the vagrant user is located in /home/vagrant/.ssh inside the vagrant machine, which enables to ssh into the vagrant box.
As you are mounting your current directory to /home/vagrant, all the contents of /home/vagrant are over-written and there is no authorized key file.
Change the mount path to anything except /home/vagrant, and you will able to ssh into the machine. As example
config.vm.synced_folder '.', '/home/vagrant/somepath'

Shared NFS folder is empty on Vagrant box

I'm working on a project and trying to setup the environment. In the Vagrantfile there is:
config.vm.synced_folder "./", "/vagrant", type: 'nfs'
config.vm.network "private_network", ip: "192.168.33.10"
I ssh into the box/guest, but can't see any of the files from the share. My /etc/exports looks okay:
# VAGRANT-BEGIN: 1000 14948e9b-4304-4359-9e8e-674f4ae10415
/home/{my_username}/open 192.168.33.10(rw,no_subtree_check,all_squash,anonuid=1000,anongid=1000,fsid=743045029)
# VAGRANT-END: 1000 14948e9b-4304-4359-9e8e-674f4ae10415
My UID on the box/guest when I ssh is 500, but on the host is 1000. I tried to add the following lines to my Vagrantfile to make it match up:
config.nfs.map_uid = Process.uid
config.nfs.map_gid = Process.gid
But, still no luck. The host is Ubuntu 14.04 LTS, the box is bento/Centos-6.7. There are no error msgs during vagrant up. But, it doesn't list the folder being synced:
[default] Mounting NFS shared folders...
{There should be some msg about the folders here right?}
[default] VM already provisioned. Run `vagrant provision` or use `--provision` to force it
EDIT: Here is the relevant info from debug:
INFO synced_folders: Synced Folder Implementation: nfs
INFO synced_folders: - /vagrant: ./ => /vagrant
INFO synced_folders: Invoking synced folder prepare for: nfs
INFO warden: Calling IN action: #<VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings:0x00000001b38818>
But, later, there is no mention of the folders:
INFO interface: info: Mounting NFS shared folders...
DEBUG ssh: Checking whether SSH is ready...
DEBUG ssh: Re-using SSH connection.
INFO ssh: SSH is ready!
INFO guest: Execute capability: mount_nfs_folder (redhat)
DEBUG guest: Searching for cap: mount_nfs_folder
Is there anything in particular I should be looking for?
Also, I did check if nfs is running:
service nfs-kernel-server status
and got:nsfd running
And showmount -e gives me:
/home/{My username}/open 192.168.33.10
So... if a run ls -l /vagrant on the guest I can see the shared files! So, how do I access them?

vagrant ssh fail when using synced_folder

I want to mount a local directory relative to my vagrant file inside the vm. However, when I do that,
vagrant ssh
No longer works -- private key fails. I am not sure why ssh suddenly fails.
help? (if it matters: I am trying to mount the directory my Java artifacts compile to).
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
config.vm.box = "ubuntu/trusty64"
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.cpus = 1
end
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.synced_folder "target/", "/home/vagrant"
end
As you try to sync directly on /home/vagrant in the VM, you need to make sure your target directory contains a .ssh folder with the authorized_keys
When you vagrant up the VM, vagrant will ssh and create this directory for you but when going through the sync_folder part, it will replace all the content from /home/vagrant with your host target/ so loosing what it did create before.
If you really really want to sync on /home/vagrant what you could do is run first without the sync, copy all files that have been created (.ssh/, .bash ...) into your target directory and then you should be able to rerun with the sync on /home/vagrant. (Note: I did not try that and honestly would not recommend to sync on /home/vagrant directly as if you install other soft from provisioning or other, you might run into issues later)

Cannot mount vagrant synced folder with nfs

I managed to setting up my Symfony2 project inside a ubuntu vagrant box. But it takes around 20 seconds to load the website through it's webserver. After some research, i came up with using nfs for the sync folder. Here're my setting from Vagrantfile:
config.vm.network "private_network", ip: "192.168.56.101"
config.vm.synced_folder ".", "/vagrant", :nfs => true, :mount_options => ["dmode=777","fmode=777"]
After starting de vagrant box i get the following error
==> default: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'dmode=777,fmode=777' 192.168.56.1:'/Users/marcschenk/Projects/teleboy.ch' /vagrant
Stdout from the command:
Stderr from the command:
stdin: is not a tty
mount.nfs: an incorrect mount option was specified
The VM seems to work, but the synced folder's obviously empty. What did i wrong?
My setup:
Vagrant 1.6.5 & Virtualbox 4.3.18
Host: OS X 10.10
Guest: Ubuntu 12.04
Found the solution for the problem here https://github.com/mitchellh/vagrant/issues/2546
The correct syntax for vagrant version 1.3 to 1.6 is:
config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777","fmode=777"] }

Resources