docker 容器自定义 hosts 网络访问

在 docker-compose.yml 中增加 extra_hosts 关键字就可以将数据写入到容器的 /etc/hosts。

extra_hosts
添加主机名映射。

extra_hosts:

  • “somehost:162.242.195.82”
  • “otherhost:50.31.209.229”
    将会在/etc/hosts创建记录:

162.242.195.82 somehost
50.31.209.229 otherhost

注意:如果指向的是本机,不要写容器的ip,(因为IP重启后会变,除非你给容器设置固定ip)
而是写宿主机的ip,如192.168.xxx.xxx

发布了48 篇原创文章 · 获赞 36 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/qq_34924407/article/details/85654764