更新时间:2022-06-22 06:59:37
查看-add-host
标志: https://docs.docker.com/engine/reference/run/#managing-etchosts docker
命令的
$ docker run --add-host = smtp:127.17.0.1容器命令
在Docker中, / etc / hosts
不能在运行时被覆盖或修改(安全功能)。您需要使用Docker的API,在本例中为-add-host
来修改文件。
In Docker, /etc/hosts
cannot be overwritten or modified at runtime (security feature). You need to use Docker's API, in this case --add-host
to modify the file.
对于 docker-compose
,使用 extra_hosts
选项。
整个连接到主机中运行的服务问题,请参阅此GitHub问题中的讨论: https:/ /github.com/docker/docker/issues/1143 。
For the whole "connect to services running in host" problem, see the discussion in this GitHub issue: https://github.com/docker/docker/issues/1143.
解决此问题的常用方法是使用-add -host
,其中包含主机的Docker网关地址,例如-add-host = dockerhost:172.17.42.1
。在上面的问题中检查某些脚本,这些脚本可以找到正确的IP并启动您的容器。
The common approach for this problem is to use --add-host
with Docker's gateway address for the host, e.g. --add-host="dockerhost:172.17.42.1"
. Check the issue above for some scripts that find the correct IP and start your containers.