Home Fix vagrant-hostmanager 127.0.0.1 with docker
Post
Cancel

Fix vagrant-hostmanager 127.0.0.1 with docker

Version 2.0.+ of Vagrant default hosts to 127.0.0.1 in /etc/hosts with docker provider

So if you have recently upgraded Vagrant like I did to a version greater than 2.0.X and you regularly use vagrant plugin vagrant-hostmanager to keep track of your host alias in both /etc/hosts in your local machine and docker containers

It’s highly likely that whenever you run

1
vagrant up my-favourite-machine

Results in having part of /etc/hosts looking like this

1
2
3
## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9
127.0.0.1	my-favourite-machine
## vagrant-hostmanager-end

When it should look similar to this:

1
2
3
## vagrant-hostmanager-start id: 3ee2758e-bdf2-4086-b999-0ecea4a973f9
172.17.0.2	my-favourite-machine
## vagrant-hostmanager-end

This breaks all sort of configurations that require local dns resolvers specially when linking across containers

So current solution as far as I can see, having an issue open on the github repo without answer so far is actually to downgrade Vagrant, as I’m not taking advantage of any introduction brought up by versions of Vagrant greater than 2.0+

The solution passes by the downgrade to a stabler and on previous major version.

Since we keep Vagrant versioned at 1.9.1 here at Fiercely in our Jenkins Slaves, I can confidently assure you this versions is stable and useable with vagrant-hostmanager when using a docker provider.

I’m not unable to test, as I don’t have access to VMWare, but downgrade should also fix the issue of defaulting VM’s defaulting to 127.0.0.1 when using Vmware as a Vagrant Provider along with vagrant-hostmanager. (another open issue at the plugin github repo for the time being)

How to downgrade Vagrant on Linux to a different version.

First remove it according to Hashicorp’s documentation

Removing vagrant

1
2
    rm -rf /opt/vagrant
    rm -f /usr/bin/vagrant

Don’t eliminate your ~/.vagrant.d , there is no need to do it

Then let’s download version 1.9.1 (or whatever you prefer), but can confirm to fix this issue it works on version: 1.9.1

If you came just looking for How to downgrade Vagrant on Linux to a previous version than install whatever version you wish

Now let’s download and install the Vagrant version we wish

Instatling Vagrant On Debian/Ubuntu:

1
2
3
4
5
6
7
    #Download
    export VAGRANT_VERSION=1.9.1
    wget https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb -P /tmp
    #Install
    sudo dpkg -i /tmp/vagrant_${VAGRANT_VERSION}_x86_64.deb
    #Remove Download
    rm /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb

Installing Vagrant On CentOS/Fedora/Redhat

1
2
3
4
5
6
7
    #Download
    export VAGRANT_VERSION=1.9.1
    wget https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm -P /tmp
    #Install
    sudo rpm -ivh /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm
    #Remove Download
    rm /tmp/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm

You now need to update the plugins

1
vagrant plugin update

If the above gives you any conflict, you might as well remove plugins to reinstall in case of incompatibility in versions

1
2
vagrant plugin expunge
#Answer Yes to the following questions regarding removing the plugins

Then reinstall, in this vagrant-hostmanager

1
vagrant plugin install vagrant-hostmanager

And now when you vagrant up favourite-machine

Both your /etc/host at local machine and VM/container should contain the correct values, and not the default ones.

The opinons on this Post are solely mine and not those of my employers

This post is licensed under CC BY 4.0 by the author.