在 Dockerfile 中附加到 /etc/hosts 的最佳方法是什么

What is the best way to append to /etc/hosts within Dockerfile

不幸的是,Docker 不会在 Docker 文件

中的 运行 命令之间保留 /etc/hosts 文件

请推荐在 Docker 文件

中附加到 /etc/hosts 的最佳方法

最好不要这样做,主要是因为您将图像绑定到您的网络。相反,使用 --add-host 标志到 docker run 添加条目,例如:

docker run --add-host test:127.0.0.1 nginx