Private Network broken in Vagrant with Docker

I create a Virtualbox vm via Vagrant by using the default Docker Vagrantfile. Building the vm with vagrant up works as expected and provides a running box to work with.

I then needed the ability to forward ports and added the following to the Vagrantfile:

  • Ubuntu partitioning setup for running docker machines on windows box
  • Docker: npm install behind proxy
  • docker nginx connection refused while connecting to upstream
  • Docker exec via rancher API
  • exited: scrapy (exit status 0; not expected)
  • I can't access to kafka broker outside docker container
  • Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
      config.vm.network :forwarded_port, :host => 5432, :guest => 5432 # postgres
      # ... more port forwardings
    end
    

    This works, but i then realized that i need port forwarding in both directions. I tried to create a private network for this matter instead of forwarding each port. The following addition to the config should have done the trick:

    Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
      config.vm.network :private_network, ip: "172.17.0.2"
    end
    

    But, this triggers an error while creating the vm:

    > vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    [default] Clearing any previously set forwarded ports...
    [default] Creating shared folders metadata...
    [default] Clearing any previously set network interfaces...
    [default] Preparing network interfaces based on configuration...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] Running 'pre-boot' VM customizations...
    [default] Booting VM...
    [default] Waiting for machine to boot. This may take a few minutes...
    The guest machine entered an invalid state while waiting for it
    to boot. Valid states are 'starting, running'. The machine is in the
    'poweroff' state. Please verify everything is configured
    properly and try again.
    
    If the provider you're using has a GUI that comes with it,
    it is often helpful to open that and watch the machine, since the
    GUI often has more helpful error messages than Vagrant can retrieve.
    For example, if you're using VirtualBox, run `vagrant up` while the
    VirtualBox GUI is open.
    

    Any idea how to debug and resolve this?

    Host OS: Arch Linux

    VM OS: Ubuntu (see Vagrantfile linked above)

  • Prevent Docker from rebuilding certain parts of Dockerfile
  • How to get the output from docker run -i
  • dockerize does not delay the container initialization
  • Connection refused with kubectl on EC2 ubuntu instance?
  • docker build purely from command line
  • How do I expose Docker a Docker port via Kubernetes in Google Cloud?
  • One Solution collect form web for “Private Network broken in Vagrant with Docker”

    From the Arch Linux Wiki:

    To ensure full functionality of bridged networking, ensure that the
    vboxnetadp, vboxnetflt and vboxpci kernel modules are loaded too and
    that the net-tools package is installed.

    Kernel modules

    The issue is that the kernel modules for creating private networks in a virtual machine need to be loaded seperately:

    sudo modprobe -a vboxnetadp vboxnetflt
    

    To make this change permanent after each reboot, put the following lines in /etc/modules-load.d/virtualbox.conf:

    vboxdrv
    vboxnetadp
    vboxnetflt
    

    Packages

    net-tools needs to be installed:

    sudo pacman -S net-tools
    

    You also need the virtualbox-host-modules package in order to bring private networks to life:

    sudo pacman -S virtualbox-host-modules
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.