How to add entries to /etc/hosts in lando appserver?
Asked Answered
R

4

7

I tried this (which should not return anything):

$ lando ssh -s appserver -u root -c "echo \"10.0.0.132 pds\" >> /etc/hosts"
10.0.0.132 pds >> /etc/hosts


$ lando ssh -s appserver -u root -c "cat /etc/hosts"
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.26.0.2      8da36421fdb0
172.19.0.3      8da36421fdb0
172.18.0.4      8da36421fdb0

Which shows it was not added. When I enter as root and do it within the container, then it works.

I would like to automate this in a build script. How? What am I doing wrong?

Apparently this can be accomplished with "docker run --add-host" but how do you include this in the .lando.yml file?

Rheims answered 20/2, 2019 at 13:54 Comment(4)
Where does this IP address come from?Nd
pds' IP address was a LAN server.Procurer
have you find a easy solution?Mima
Not yet. I should look though the Lando documentation again because there were some recente updates that could have made it easier.Procurer
R
2

I googled through the Lando documentation with "etc/hosts site:lando.dev" and found a hint to the likely solution in the section Services - Build Steps. I was not able to try it yet but I see there an example with:

services:
  servicename:
    run_as_root:
      - echo "127.0.0.1 mysite.lndo.site" >> /etc/hosts

Apparently this is the proper way to append a new line to /etc/hosts inside a service container.

Rheims answered 29/4, 2020 at 17:41 Comment(1)
This no longer works likely because Docker has changed. I don't want to rebuild when it is not necessary. I guess this is done for security reasons.Procurer
G
1

/etc/hosts is managed by Docker. If you really need to add host record, then use docker run parameter:

--add-host="" : Add a line to /etc/hosts (host:IP)

Doc: https://docs.docker.com/engine/reference/run/#network-settings

Gunboat answered 20/2, 2019 at 15:40 Comment(2)
How do I insert docker run parameters in the .lando.yml configuration file?Procurer
I don't have a working .lando.yml yet but here an additional hint I received on the matter.Procurer
S
0

Lando supports proxy settings: (https://docs.lando.dev/config/proxy.html#usage)

proxy:
  web:
    - mysite.lndo.site
    - sub.mysite.lndo.site
    - bob.frank.kbox.com
    - tippecanoe.tyler.too
Smithy answered 21/11, 2019 at 22:45 Comment(1)
For convenience the IP and domain have to be in /etc/hosts. It is for accessing another stage or other resources.Procurer
P
0

I first installed vim

lando ssh --service appserver --user root --command "apt-get update && apt 
install vim -y"

and updated /etc/hosts by logging in as root

lando ssh --service appserver --user root

"lando rebuild" don't cancel the modification

Pteridology answered 14/9, 2022 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.