【问题标题】:How to add entries to /etc/hosts in lando appserver?如何在lando appserver 中向/etc/hosts 添加条目?
【发布时间】:2019-02-20 13:54:47
【问题描述】:

我试过这个(它不应该返回任何东西):

$ 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

这表明它没有被添加。 当我以 root 身份进入并在容器中执行此操作时,它就可以工作了。

我想在构建脚本中自动执行此操作。如何?我做错了什么?

显然这可以通过“docker run --add-host”来完成,但是如何将它包含在 .lando.yml 文件中呢?

【问题讨论】:

  • 这个IP地址是从哪里来的?
  • pds 的 IP 地址是 LAN 服务器。
  • 您找到简单的解决方案了吗?
  • 还没有。我应该再次查看 Lando 文档,因为有一些最近的更新可以使它更容易。

标签: docker lando


【解决方案1】:

/etc/hosts 由 Docker 管理。如果确实需要添加主机记录,那么使用docker run参数:

--add-host="" : 添加一行到 /etc/hosts (host:IP)

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

【讨论】:

  • 如何在 .lando.yml 配置文件中插入 docker run 参数?
【解决方案2】:

Lando 支持代理设置: (https://docs.lando.dev/config/proxy.html#usage)

proxy:
  web:
    - mysite.lndo.site
    - sub.mysite.lndo.site
    - bob.frank.kbox.com
    - tippecanoe.tyler.too

【讨论】:

  • 为方便起见,IP 和域必须在 /etc/hosts 中。它用于访问另一个阶段或其他资源。
【解决方案3】:

我使用“etc/hosts site:lando.dev”搜索了 Lando 文档,并在 Services - Build Steps 部分找到了可能解决方案的提示。我还不能尝试,但我看到了一个例子:

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

显然这是在服务容器内的 /etc/hosts 中追加新行的正确方法。

【讨论】:

    猜你喜欢
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2020-07-01
    相关资源
    最近更新 更多