-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Add container host names to /etc/hosts
#2335
Comments
This would be interesting, but it would conflict with #2267. |
As written, one way would be to have a config option, how to deal with |
So, basically, people could switch between two behaviors:
Is that right? Also, another question: what about multi-tenant installs? I.e. when I run containers for multiple different persons, they will see each other's containers in /etc/hosts... How do you suggest to address that? |
Also, doesn't the links branch make it so that containers must be explicitly be exposed or linked to communicate? |
Oh, and I think that we discussed about a flag to switch between "open communication between containers" and "only linked containers can communicate", so maybe we could have something like this (in post-link world):
|
Ok, so further assuming post-links land, would "open communication mode" |
Tianon, what do you mean with »or would it also contain the container "name"«? If you mean the host name passed by There is no problem though putting both names in into |
There's the hostname, yes, but then there's also the container name (in a post-links world): #2162 |
By the way, does LXC use its own DNSmasq server, which Docker does not use? The package
But Docker uses different IP addresses 172.…. My point is, DNSmasq could be used and a file be added matching the host name and IP address, which DNSmasq should use then. |
The |
@tianon What is the status of this issue? Should we close it or imlpement it? I like the idea to have a /etc/hosts filled with all linked container's ips/hostname/name.hostname/name. What do you think? |
/cc @jpetazzo |
I think it would be a really sweet optional addition, especially if it includes all the container IDs and then hostnames for containers where that's specified. |
I would love to be able to reach every container by name instead of having to docker inspect | grep IP et cetera. I saw there is a -dns option. Does anyone know a script snippet that makes a Docker container register itself with a dnsmasq instance? |
I know clients might cache a DNS lookup, so it's not the most reliable way to do service discovery, but don't know a good alternative. The services I'm running via docker need an IP address or hostname in a config file and I want to point them to other containers. Here's a little hack that seems to be working for me. I call this script after stopping or starting any containers, it updates /etc/hosts and sends "kill -HUP dnsmasq". Then I run each container with -dns pointing to the docker host (eg, your vagrant vm). |
+1
Personally I'd make the hostname in /etc/hosts the link name. When linking we're populating the environment with variables based on the link name ($_PORT_3306_TCP_PORT, $_PORT_3306_TCP_ADDR), so it seems more consistent to put that in /etc/hosts as well. |
Yes this would be a nice feature 👍 |
With the PR #5525 we are now writing linked containers names into the etc hosts file. I believe this resolve this issue as well. We voted for only adding linked containers names instead of all containers because it is a better longer term tradeoff for multi tenancy and other usecases. |
Sorry if this is not the right place to bring this up, but I wanted a clarification. What I mean is that so I can not either do: The same is true if I set the name of the container: Of course if I get the container's IP address (via, say, From what I have read @jpetazzo's Piperwork seems a tool to do the job. Another tool is @bnfinet's docker-dns. |
Amen. |
Bump. This would be really nice. For instance, being able to mysql into my db container from the host would be great and prevent me from ever needing to docker exec -it NAME bash |
For the record:
@MichaelMackus you're asking for something different - this issue is container<->container connectivity. |
@aidanhs thanks - resolvable looks like exactly what I was looking for! |
Could this be made a configuration option for Docker instead? So should the default bridge have this feature or not? And then the host can decide? In this way it can be made backwards compatible, with Docker 1.9 hosts just have to enable it, while the new default would be that it is disabled? |
+1 |
+1 for Docker host being able to resolve containers running on it by their names. |
@strarsis This is already implemented when using user-defined networks via DNS. |
Docker should be able to resolve containers via their |
The containers should be reachable by their host names from other containers.
Creating two containers with
and
it should be possible, to run
ping test2
. That is useful, when having a database image and running only one container from it. If the container crashes or a new one is started from an updated image, I do not want to update all the configuration files of my containers using that database server.If no hostname is specified, the container ID is used by default for the host name, so every container has one already.
As
/etc/hosts
is bind mounted, couldn’t this be used for this by adding or removing entries.I saw that for LXC(?) a DNSmasq instance is running. Maybe that could be used for that too. paultag in #docker on <irc.freenode.net> told me, that a FQDN is needed for that. Just provide a default
dockernet
for example.If that is not wanted for all use cases, Docker should provide a config option for that.
The text was updated successfully, but these errors were encountered: