docs
docs copied to clipboard
Multiple methods to contact other containers
Is this a docs issue?
- [X] My issue is about the documentation content or website
Type of issue
I can't find what I'm looking for
Description
There is a lot of information scattered online on the difference between service names, container names, hostnames etc. and how each is used to contact another container.
Location
https://docs.docker.com/compose/networking/
Suggestion
A table that identifies the various ways to contact another container.
They all rely on the container having a /etc/hosts mapping or reaching out to a DNS service (like the internal one Docker can provide) AFAIK.
It's a bit more problematic when connecting across networks on the same system (host to container, container to host, container to container via published ports on host IP) and how that differs with userland-proxy setting of the Docker daemon. I've put together a table for that in a separate docs issue.
It also depends if you're using compose (default network does not use the docker0 legacy bridge) vs CLI like docker run which defaults containers to the docker0 legacy bridge. That affects routing too.
Avoid docker0 network when this matters, your bridged containers can reach each other on the same network via hostname, and you can add other hosts if necessary.
One other caveat you can run into is if you're on Windows for example with WSL2, Docker is run on a separate VM where --network host is available but due to the VM isolation isn't reachable by WSL2 or the Windows host.
- The windows host cannot reach the private docker bridge networks within WSL2, only published ports via localhost.
- This can be a slight issue if you want to run your own DNS locally that maps an FQDN to localhost for the Windows host, but the containers would be incompatible to resolve to 127.0.0.1 to reach the other containers, thus split DNS support is required, or explicit
/etc/hostsmappings (which will be checked first before a DNS query, except in the past there was some issues with Alpine and Go where that was not the case).
...It can be complicated to document as you can see. Depends where you want to draw the line without overwhelming / confusing the user with those edge cases.
There hasn't been any activity on this issue for a long time.
If the problem is still relevant, mark the issue as fresh with a /remove-lifecycle stale comment.
If not, this issue will be closed in 14 days. This helps our maintainers focus on the active issues.
Prevent issues from auto-closing with a /lifecycle frozen comment.
/lifecycle stale
Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.
If you have found a problem that seems similar to this, please open a new issue.
/lifecycle locked