-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
how to connect to Docker host from container #8395
Comments
Several ways:
Add a static address to your host's |
👍 any convenient official api is much needed. |
This is my opinion as someone new to docker, so take it for what its worth.
Dockerfile
Command line
While this is a *nix specific workaround, and direct support from within docker would certainly be nice, I don't think this will suddenly become unusable with a future docker release. I think people are safe to use this for the time being. Perhaps someone more official than me could confirm or deny these thoughts? |
Holy cow! this looks pretty neat. |
Another possibility I forgot to mention. In addition to adding a static IP to the loopback interface, you can also just hard set the IP docker uses for the |
I also wrote http://github.com/erikh/tfip to make parsing of these values simpler, fwiw. Going to leave this open because we really should address this. |
rather than setting an Environment variable, you can also do |
and there's some docs, as it gives an example of using |
Cool, thanks for adding @SvenDowideit |
@SvenDowideit |
Many suggestions have been brought to this issue, and show that no code change is required to address the use case: I'm closing this. |
@icecrime That there is no code change needed, does not entail that the issue is solved. If you look at #1143, you can see that there still is quite some interest in an officially supported solution. I.e. the issue could be 'fixed' by having a solution documented. To me sll these solutions sound like workarounds that may or may not work in the future. Since I originally opened this issue because #1143 had been closed, I will refrain from creating the next issue. |
Issue: I need a reliable way to access a service running on the host from a docker container
This is an officially supported solution that will work in the future. Sorry, I don't see what's missing there. |
@icecrime thank you! |
How can you do this with docker-compose and docker-swarm? |
Link to the docs has changed from #8395 (comment). This is the new one. |
That link seems outdated already as well. I can only find those commands in these old 1.3 docs: https://docs.docker.com/v1.3/reference/commandline/cli/ |
Here is the correct link: https://docs.docker.com/engine/reference/run/#managing-etc-hosts |
Except this solutions fails. The hostip command returns the correct IP inside the container, however in the example it's run in the host, and so returns the host's gateway, which is not necessarily the same as the host ip from within the container. In my case this happens:
A correct solution to this problem imo should work inside a container that has no executables. I shouldn't have to run some hacky bash command from within the container to get the IP |
I agree. The snippet provided doesn't suggest running the commands from "within the container" to get the IP, though you could do that if you want/need to, using the same tools... The solution quoted above
is close, but also wrong as you've noticed. It incorrectly returns the docker host's default route next hop (aka gateway IP), instead of the local machine's IP. I don't know what the author of it was thinking. It's totally wrong for the question being asked. The question everyone is asking is "what IP address do I connect to, inside a container, to reach services on the docker host?" The answer depends on your On the docker host... these return the correct values.... export DOCKER0_INTERFACE_IP=$(ip route list dev docker0 | awk 'NR==1 {print $NF}')
export DEFAULT_ROUTE_INTERFACE_IP=$(ip route list | awk '/default/ {print $3; exit}') Plumbing them to |
Although I really appreciate this answer, it does not work in OS X. And I can't imagine it working in windows. A docker coded solution would be much appreciated. For those of you on os x, I was able to do this by creating an alias as mentioned in the 2nd comment of this issue:
|
What's about the The solutions proposed here are useful (albeit very hackish) workarounds when you deal with Dockerfiles only, but when you handle them via The built-in addition of a So @icecrime I can't see how this issue can be considered solved, for now. At least, when you're using |
@reallistic Is it possible to explain why previous way did not work? I tried as well and same result. @icecrime Can you also give a clue why it does not work? |
@cemo Mac OS X does not provide the same |
I have a problem and I wanted to know if this works - instead of docker0 ip address to communicate to docker host, can I use the LAN/public IP of the docker host to talk from the container to host ? |
#1143 is closed but not resolved.
I do not know how to reopen it, so I created this issue.
Summary: I need a reliable way to access a service running on the host from a docker container.
Therefore I need the IP address of the host that is reachable from the container
Scenario: I have a configuration DB that runs on the host and the docker container should get its configuration (and perhaps even some updates) from the DB.
The text was updated successfully, but these errors were encountered: