Update /etc/hosts at rebuild


(Martial) #1

Hello,

I try to add a command to the app.yml file to add an entry to the host file in the docker container at the rebuild.
But this command never works and i can’t understand why :zipper_mouth_face:

run:  
   - exec: "echo '192.168.0.1 custom.domain.fr' >> /etc/hosts"

Any how to update the /etc/hosts at rebuild ?


(Eli the Bearded) #2

Pretty sure your quotes are wrong.

run:  
   - exec: echo '192.168.0.1 custom.domain.fr' >> /etc/hosts

The issue seems to be, that command will work just fine, but will be lost on container start. Go ahead and enter the container, run the command by hand, then restart it:

./launcher enter app
echo '192.168.0.1 custom.domain.fr' >> /etc/hosts
grep custom /etc/hosts
192.168.0.1 custom.domain.fr
exit
./launcher restart app
./launcher enter app
grep custom /etc/hosts

Not quite sure what process is rewriting the /etc/hosts file.

This works:

./launcher start app
docker exec -it app bash -c "echo 192.168.0.1 custom.domain.fr >> /etc/hosts"

But you’d need to do that every start. (And if you try to modify launcher to do that for you, launcher will get upset when it can’t update itself with git. Ask me how I know this? I’ve done that.)


(Eli the Bearded) #3

Okay, I figured it out. You cannot use the yml file because /etc/hosts is created at runtime by Docker itself. To add entries to it, you need to use the --docker-args option to launcher at rebuild time.

./launcher rebuild app  --docker-args "--add-host  extra.dns:8.8.8.8"
./launcher enter app
grep extra /etc/hosts
8.8.8.8 extra.dns

There are a slew of dns / resolver / similar options for docker run, and those are the ones you need to use for this sort of stuff.


(Martial) #4

Hummm ! Intersting :+1:
Meaning I cannot use /admin/upgrade to update to Discourse :zipper_mouth_face:


(Eli the Bearded) #5

Well, here’s a slightly messy alternative.

Changes to /etc/hosts file are effectively immediate for the system. Docker creates the file at boot time, while setting up all of the container internal networking. But after that Docker leaves it alone. A “plug-in” that inserted itself into late system boot could add values to the /etc/hosts file. (Or could be a script created via yml.)

I might try to tackle that later today.


(David Taylor) #6

/admin/upgrade shouldn’t touch the /etc/hosts file - it just updates stuff within the docker container, it doesn’t do a full rebuild.


(Martial) #7

Even the update on docker_manager ? :face_with_raised_eyebrow:


(David Taylor) #8

Yep, updating docker_manager just updates the docker_manager discourse plugin, which contains all the scripts for updates. It still doesn’t even restart the container, let alone rebuild it.


(Eli the Bearded) #9

Huh, add to list of things I didn’t realize. Never paid that much attention to what was happening, since it always just worked. :blush: