machine icon indicating copy to clipboard operation
machine copied to clipboard

Add /etc/hosts entry for docker machine

Open RaasAhsan opened this issue 10 years ago • 44 comments

When a docker machine is brought up, is there any way to automatically add in a /etc/hosts entry for the IP of that machine? I want some common keyword I can connect my services to rather than an IP. I can do this manually but it would be a neat feature.

RaasAhsan avatar Sep 02 '15 04:09 RaasAhsan

+1

zakuni avatar Sep 02 '15 13:09 zakuni

I think this is a bit out of scope for machine CLI, but it makes me want a plugin model which could accommodate this, e.g. git hook style.

nathanleclaire avatar Sep 02 '15 22:09 nathanleclaire

+1

josephabrahams avatar Sep 06 '15 03:09 josephabrahams

+1

FugDev avatar Sep 12 '15 08:09 FugDev

So I noticed the Parallels provider does this by default, but not Virtualbox. When I create a machine with the Parallels driver it adds an entry like so:

xx.xxx.xxx.xxx  <machine-name>.shared <machine-name> #prl_hostonly shared

This is extremely convenient for the less technical people by automating this step.

I also found that it gradually increments the vm's IP with Parallels, but Virtualbox appears to always grab the lowest available IP in the pool. So if you had a machine on 192.168.99.100, stop it, then create another new box, the new box will be on 192.168.99.100 rather than .101.

So it seems this is more driver related than docker-machine related.

bryannaegele avatar Sep 28 '15 16:09 bryannaegele

this would also be advantageous for other tools, like docker-py, that are trying to assert the TLS hostname.

the-destro avatar Sep 30 '15 02:09 the-destro

+1

BlueHotDog avatar Sep 30 '15 18:09 BlueHotDog

+1

hassek avatar Oct 09 '15 23:10 hassek

+1, but the hook way seems more interesting

gcuisinier avatar Oct 31 '15 18:10 gcuisinier

+1 or even just a way to control which IP it chooses to use when starting a specific machine (preferably a stable IP per-machine) ...then I could at least hand edit my /etc/hosts file once and be done

anentropic avatar Nov 14 '15 17:11 anentropic

Specify an IP is not always possible. For example, in the case of Amazon, the IP is different each time you start an instance. This is the same for GCE I think, an probably for all cloud provider. To be complete, Amazon and GCE have the notion of eternal IP to keep it at each restart of the instance, but it is more expensive, and you cannot choose the IP anymore (the IP is provided by the cloud provided, in a certain range).

The addition of an entry in a the /etc/hosts is a better solution because it is not bound to a particular driver, and therefore more interesting.

But, IMHO, a hook system is even better, because more flexible. You this, you can do a lot of think :

  • Add an entry in hosts file
  • OR, Register the machine resolution in a dynamic DNS, and so the resolution is not only bound to an unique machine
  • Add the machine in a monitoring tools
  • ...

What do you think ?

gcuisinier avatar Nov 15 '15 07:11 gcuisinier

hook system - great being able to specify a specific ip for virtualbox would be a handy quick hack though

anentropic avatar Nov 15 '15 12:11 anentropic

I am not sure that is a quicky hack. To force the IP, I think you have to disable the VBox DHCP server and provide an other one that provide your IP.

Or to run command inside the VM to configure the network adapter (like Vagrant do I think).

gcuisinier avatar Nov 16 '15 00:11 gcuisinier

+1

heycalmdown avatar Nov 26 '15 22:11 heycalmdown

+1 Trying to get TLS to cooperate with docker-py for automation tools would be way easier.

ghost avatar Dec 14 '15 04:12 ghost

+1

Foo42 avatar Jan 04 '16 09:01 Foo42

+1 would improve my automation immensely.

jandre avatar Jan 05 '16 14:01 jandre

+1

dancompton avatar Jan 10 '16 21:01 dancompton

+1

sarink avatar Jan 13 '16 03:01 sarink

Had the same concern :+1:

At the moment I'm using a custom tool for this (https://github.com/bamarni/docker-machine-dns).

bamarni avatar Jan 17 '16 13:01 bamarni

I created a simple script for which I added an alias in my ~/.profile (Tested only on OSX):

alias de=". ~/bin/de.sh"

https://gist.github.com/mjumelet/1cb8f0531243ee5733a6

Since it needs to modify /etc/hosts it will ask for your password

mjumelet avatar Jan 29 '16 09:01 mjumelet

+1

iamKurt avatar Feb 01 '16 05:02 iamKurt

+1

astewart-twist avatar Apr 01 '16 00:04 astewart-twist

+1

ernestm avatar Apr 05 '16 14:04 ernestm

What about a simple sed replacement for the hosts file added to .bashrc?

grisevg avatar Apr 12 '16 03:04 grisevg

+1

mateusz-lisik avatar Jul 10 '16 20:07 mateusz-lisik

+1

agusti-t avatar Aug 04 '16 12:08 agusti-t

+1

charleskun avatar Sep 12 '16 06:09 charleskun

+1

BeaverCC avatar Sep 15 '16 08:09 BeaverCC

+1

apophizzz avatar Oct 01 '16 17:10 apophizzz