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:

  • cannot use curl to load docker image from a tarball using docker api
  • Connecting to SQL Server Express from within Docker Container gives an error occurred evaluating the password
  • Choosing the right AWS Services and software tools
  • docker run python from container
  • Hyperledger Docker endpoint not found
  • Migrating Established TCP connection with docker containers
  • 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)

  • DockerToolbox for win7 service unavailable error
  • gcloud auth login with Docker does not work as it says in documentation
  • Changing the log level for a selenium node running in docker
  • Using a Docker image to build and deploy as part of a build matrix
  • Change process limit of open file descriptors inside a container [duplicate]
  • Do I need to rebuild image when parent image is updated?
  • 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.