machine icon indicating copy to clipboard operation
machine copied to clipboard

Question: Persisting docker /etc/hosts file changes after Docker host restart

Open iamKurt opened this issue 10 years ago • 13 comments

Hi,

This is probably just a newbie question instead of an actual issue -- is there a way to restart the docker host while persisting the changes made to the /etc/hosts file?

Thanks, Kurt

iamKurt avatar Dec 24 '15 20:12 iamKurt

By docker host, what I mean is the Linux VM that is created by docker-machine on which the docker daemon is running.

The docker run command allows you to specify a --add-host option. Is there something equivalent for docker-machine create? This way, the docker host will have the host mapping of an internal private registry.

Thanks!

iamKurt avatar Dec 31 '15 04:12 iamKurt

I thought that this was going to be merely a trivial annoying issue, but it turns out that this also prevents pushing into a private repository. Tagging and pushing via the IP address will work but if we want the host name to be mapped to the IP address then we would need to be able to persist that host file entry between Docker host restarts.

How are other folks solving this issue?

iamKurt avatar Jan 12 '16 23:01 iamKurt

@nathanleclaire Any ideas about this one?

iamKurt avatar Jan 21 '16 06:01 iamKurt

You mean /etc/hosts in the VM?

nathanleclaire avatar Jan 21 '16 23:01 nathanleclaire

Yes. Is there a way to tell docker-machine to create a host vm or update one with mappings in the host file?

iamKurt avatar Jan 22 '16 05:01 iamKurt

It's not possible currently. You could probably use docker-machine ssh after create is done if desired.

nathanleclaire avatar Jan 27 '16 03:01 nathanleclaire

Thanks for the information, Nathan. I will say that it is going to be hard to have to modify the /etc/hosts file each time the host VM is restarted. Now I'm wondering whether there is a way to override the docker-machine start/restart script to include automatically scripting these modifications. Good idea or bad one?

Is this the same for any custom certs that we have? Ideally, I would like to be able to add a directory on the Docker VM to the effect of /etc/docker/certs.d/my.docker.reg.com/ and then store a cert for my registry there. I am not really seeing how Docker Machine's create can handle this situation. Am I missing an optional argument that will allow for this?

Thanks again for the info, @nathanleclaire!

iamKurt avatar Jan 27 '16 21:01 iamKurt

Thanks for the information, Nathan. I will say that it is going to be hard to have to modify the /etc/hosts file each time the host VM is restarted. Now I'm wondering whether there is a way to override the docker-machine start/restart script to include automatically scripting these modifications. Good idea or bad one?

Unfortunately there is no way to do this in Machine itself (without modification) today AFAIK but you could potentially wrap machine start and restart in a little script / alias if the need is strong.

Is this the same for any custom certs that we have? Ideally, I would like to be able to add a directory on the Docker VM to the effect of /etc/docker/certs.d/my.docker.reg.com/ and then store a cert for my registry there. I am not really seeing how Docker Machine's create can handle this situation. Am I missing an optional argument that will allow for this?

Take a look at https://github.com/boot2docker/boot2docker#installing-secure-registry-certificates. B2D accounts for this and you should be able to persist certificates in the VM if installed correctly.

nathanleclaire avatar Jan 27 '16 21:01 nathanleclaire

Thanks, Nathan! The boot2docker link looks interesting. I'll play around with B2D (in the next day or so) to see whether it solves the problem.

iamKurt avatar Jan 27 '16 22:01 iamKurt

This issue #1792 is related.

iamKurt avatar Feb 01 '16 05:02 iamKurt

+1

wyy0117 avatar Aug 20 '20 06:08 wyy0117

+1

will-beta avatar Jan 21 '21 06:01 will-beta

+1

jlainema avatar Jun 08 '21 05:06 jlainema