Tell Vagrant the ip of the host machine

前端 未结 3 1859
日久生厌
日久生厌 2020-12-23 11:37

I am using a vagrant box as a development machine for a project with an odd dependency I can only seem to install on ubuntu.

I created my database and have my app co

相关标签:
3条回答
  • 2020-12-23 12:14

    As an alternative to Matt's solution, you can also use private networks your Vagrantfile.

    If you add a line such as:

    config.vm.network "private_network", ip: "192.168.42.10"
    

    Vagrant will add a second adapter to the virtual machine and hook it up to host-only adapter on that subnet.

    This way you can then let database.yml simply point to 192.168.42.1 all the time (in this example).

    0 讨论(0)
  • 2020-12-23 12:16

    Not sure, if it will work for everybody, though all my virtual box machines see host machine by this "magic" ip:

    10.0.2.2
    

    Don't know if it's always static, though for me works and it's very convenient - I can use laptop at home, from office - having assigned different IPs to me by routers, but my VMs know the "trusty name" of their master

    0 讨论(0)
  • 2020-12-23 12:30

    According to this, you can reach the host through the VM's default gateway.

    Running netstat -rn on the guest should give you the relevant info, on my machine changing your code above to the following looks like it would get things going for you:

    # database.yml
    development:
      host: <%= `netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10` %>
    
    0 讨论(0)
提交回复
热议问题