[英]host.docker.internal vs container name when referencing ip
When defining services in a docker-compose file, when do I use host.docker.internal
for the host's ip and when do I need to use the container's name?在 docker-compose 文件中定义服务时,我什么时候使用host.docker.internal
作为主机的 ip 以及何时需要使用容器的名称?
All possible communication flows are illustrated here:此处说明了所有可能的通信流程:
(1): non-containerized process communicates with a container (1):非容器化进程与容器通信
(2): container communicates with another container (2):容器与另一个容器通信
(3): the opposite direction of (1) (3):与(1)相反的方向
(1): container must forward port to host, so the non-containerized process can access it (1):容器必须将端口转发给主机,这样非容器化的进程才能访问它
services:
c1:
...
ports:
- hostport:containerport
(2): container c1 just use the service name (container name - c2) to communicate with c2 (2):容器c1只是使用服务名(容器名-c2)与c2通信
(3): container c2 must Use host.docker.internal
to communicate with host (3):容器c2必须使用host.docker.internal
与主机通信
If you want to connect from a container to a service on the host, use host.docker.internal
.如果要从容器连接到主机上的服务,请使用host.docker.internal
。 Be aware, that this special DNS name is only available on Windows and macOS.请注意,这个特殊的 DNS 名称仅在 Windows 和 macOS 上可用。
Use the container name for networking between containers.使用容器名称在容器之间建立网络。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.