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?
All possible communication flows are illustrated here:
(1): non-containerized process communicates with a container
(2): container communicates with another container
(3): the opposite direction of (1)
(1): container must forward port to host, so the non-containerized process can access it
services:
c1:
...
ports:
- hostport:containerport
(2): container c1 just use the service name (container name - c2) to communicate with c2
(3): container c2 must Use host.docker.internal
to communicate with host
If you want to connect from a container to a service on the host, use host.docker.internal
. Be aware, that this special DNS name is only available on Windows and macOS.
Use the container name for networking between containers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.