6

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?

ñull
  • 504
  • 4
  • 17

4 Answers4

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.

ñull
  • 504
  • 4
  • 17
  • 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. – ñull Jun 20 '22 at 17:25
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

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • 2
    How do I insert docker run parameters in the .lando.yml configuration file? – ñull Jan 29 '20 at 19:30
  • I don't have a working .lando.yml yet but here an [additional hint](https://github.com/lando/lando/issues/1477#issuecomment-465585030) I received on the matter. – ñull Oct 19 '22 at 11:10
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
  • For convenience the IP and domain have to be in /etc/hosts. It is for accessing another stage or other resources. – ñull Jun 05 '20 at 11:19
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

stloc
  • 1,508
  • 1
  • 16
  • 26