方法一:

直接进入容器中修改/etc/hosts

缺点:重启容器后,增加的内容会丢失

方法二:

制作镜像的时候,直接修改。

限制:

  1. 需要是root用户,需要在容器中安装sudo

  2. 增大了镜像大小

方法三:

使用docker run运行一个新的容器的时候,通过参数 --add-host来添加域名和IP信息到容器的/etc/hosts文件中。例如:

docker run --add-host=myhostname:10.180.8.1 --name test -it debian 

注意:

  1. --add-host参数最好在--name后面,避免启动报错

方法四:

在docker-compose.yml文件中,通过配置参数extra_hosts实现。例如:

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

相关文章:

  • 2021-12-07
  • 2022-02-05
  • 2021-11-04
  • 2022-02-07
  • 2021-07-14
  • 2022-01-19
  • 2021-09-27
  • 2021-12-18
猜你喜欢
  • 2021-11-06
  • 2021-12-26
  • 2021-08-16
  • 2022-12-23
  • 2021-12-03
  • 2022-02-01
相关资源
相似解决方案