-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service can't be reached by defined hostname #2925
Comments
Adding depends_on (in slave to master) does not fix the problem. |
Looking at
The first comes from the service name, and the second is the container's short ID. I think that by default Compose doesn't create aliases based on hostnames. May I ask what you're trying to accomplish? Why can't the hostname also be "master", and why does the slave need to ping the master by hostname rather than by service name? |
Hi @jake-low, I think question is why isn't hostname defined under aliases. What is the reasoning behind this decision? |
My guess would be because
Service name and container ID are both guaranteed to be unique -- service because YAML doesn't allow multiple keys with the same name, and container ID because Docker uses a unique hash automatically. |
There was some discussion early on about using We add aliases for service name and short id to be backwards compatible and handle the common use cases. We're also adding support for your own net-aliases in #2829 As far as I know, it's not all that uncommon for the internal hostname to be unresolvable from the outside. We could probably make it another alias, but I'm not sure how we'd deal with conflicts with the service names. |
This may be a decision better left to the Engine team, as there's currently an incongruity there that needs to be solved. When you run a container with It's strange that, even though Docker gives every container a unique ID and nickname, neither is by default DNS-resolvable (based on my tests; someone feel free to correct me). |
As a Docker Composer user, I expect that whenever I set a hostname to a service, that hostname should resolve to any instance of that service. Same should apply for the service name. If these things should not work the same way, and a user should only rely on service name, then hostname definition should not be allowed in the compose file. It just creates confusion. |
That's a tall order. DNS load balancing is crude and has many unusual failure cases due to DNS's hierarchical organization and client caching behaviour [1]. This is why application-level (so-called Layer 7) load balancing schemes have become popular [2]. Tutum provides DNS-level load balancing (mapped to services, not hostnames), as seen here (last paragraph), but as the rest of the article discusses, this feature is recommended for use as a second-level load balancer. Primary load balancing duties have been assigned to a purpose-built container. |
If goal of Docker Compose is to make it easier for users to deploy a composition of services using Docker images and containers, then the file definition should be crystal clear. When a user defines a hostname to a service, it will expect that hostname to be resolvable from other services, specially when these services participate in the same network (as per my example). Since a service can have multiple instances, it is just logical that when I define a hostname to a service, that hostname resolves to multiple instances (thus using the new DNS feature in latest version). If nothing of these can be implemented today, or should not be implemented at all, then it is a matter of clarifying the documentation to state either:
|
We should probably add a warning to the docs about using |
I think it should not be allowed at all. |
That is not backwards compatible, and while it is "rarely" useful, there are still cases where it is useful in its current form, so removing it completely is not really an option. |
Then the feature should work as expected by users using Compose for the first time, by adding that information to the list of alises. Could you please be more specific where, although rare, the current form is useful? |
Agreed; I use it in a couple of cases where legacy applications expect to be able to resolve themselves by their own hostname (in these cases matching I've also used it in Kerberos environments, when the hostname on a host needs to be set to an FQDN (not necessarily unique) so that services running there can use their service principals to authenticate themselves. IMHO this feature does work "as expected" because it works the same way it does in Docker engine. Running a container with the |
Not really. With overlay network, the hostname set in a container is reachable by another container. So I disagree that it works as "expected". In fact, what users expect (and think about new users), is that when a hostname is set, specially in the case of Docker Compose, that hostname can be used by other containers. |
That's not true.
What you're saying is true if you set the
Proof that this is a swarm, and an overlay network:
|
@jake-low indeed, thanks for checking. I missed that I was setting --name too on my shell scripts. |
Any update on this issue? |
It's long been an annoyance for me that compose only creates the DNS container name aliases when using The |
This burnt almost 2 days of development on my end (with very cryptic failures). Do you by chance know if |
May I ask what is the best practice to resolve this hostname resolving issue in 2018? Should |
I solved this problem. When using The |
@slothkong
Mistake: MONGODB_URL=mongodb://mongo:27017 |
After using docker for years, this docker-compose bug is a surprise.
and as expected the container is resolvable on Surprisingly, in docker-compose, the container would be resolvable by Side note: These are two orthognal concepts: container names are meant for container management and scoped to a Docker instance, hostnames are meant for network connectivity and scoped to a network. |
thanks bro)) |
What is the last solution to dns resolve for services with hostname or domainname in the same compose file ???? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still doesn't work... |
This issue has been automatically marked as not stale anymore due to the recent activity. |
activity occurs |
This unexpected behavior still exists. The best solution I have found is this SO answer |
It's year 2020 and the issue seems to persist still. I need hostname with domainname to work. This is NOT a feature but a bug!!! Containers are spun up by docker-compose up.
works:
doesn't work:
A work around is to use |
I think the following summarizes the design philosophy and the solution to this problem: 1> the hostname, domainname tag is for modifying the hosts file. It doesn't help with dns resolution except to the container itself.
|
version: '3.9'
services:
a:
entrypoint: ["ping", "a-service"]
image: library/busybox
container_name: a-service
hostname: a-service
networks:
- share-net
depends_on:
b:
condition: service_started
#links:
# - b:b-service
b:
entrypoint: ["ping", "b-service"]
image: library/busybox
container_name: b-service
hostname: b-service
networks:
- share-net
networks:
share-net:
external: true
the internal container service names resolve failed: it doesn't work either with links. docker-compose version 1.28.0 it may be an OS relative issue, with almost same docker & compose version, it works fine in another OS ... #5991 |
Finally! :D |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
You misunderstand some important things. This example is bad:
These examples are right:
Docker using the container names to communicate between them in same network, not internal hostnames. You should use container names to communicate, not the internal container hostnames. |
@GenaANTG , agree with theory and that is what I would expect.
I expect the ping would use IP 172.30.0.3 for master and 172.30.0.2 for slave. But both are using the docker's host IP:
What do I missing and how do I make resolve the container names to they internal network IPs? Thanks |
1 similar comment
@GenaANTG , agree with theory and that is what I would expect.
I expect the ping would use IP 172.30.0.3 for master and 172.30.0.2 for slave. But both are using the docker's host IP:
What do I missing and how do I make resolve the container names to they internal network IPs? Thanks |
@zdima Note that you try ping two times master container from slave.
Everything should works as expected. This article explain everything: https://docs.docker.com/network/network-tutorial-standalone/ |
|
@GenaANTG docker-compose.yml :
I am expecting to resolve the Even the container name |
@zdima Try to run |
no difference.
Even when I open container's shell the "linked" container is not resolving to local network. |
What a mess |
Given the following docker-compose.yml file:
The following ping fails:
The text was updated successfully, but these errors were encountered: