-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
"network_mode: host" does not use the network of host machine #3800
Comments
Are you using Docker for Mac or Docker Toolbox? I don't think |
I use Docker for Mac |
@raycursif Thanks for the issue. In Docker for Mac you have a little managed VM that runs Linux. This is where Docker actually runs. D4M does "magic" to map exposed ports to your Mac's
You can see it with your own two eyes: (on Mac) $ docker run -d --net host nginx
7596dfd95ebddd0ffcfd6cdc4542df22a78b1d987e02993de7697007b2c50855
$ curl localhost
curl: (7) Failed to connect to localhost port 80: Connection refused
$ docker run --net host alpine wget -qO- localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html> Why do you want to use |
Thx for quick response and it‘s very clear ! The raison to use regards |
@raycursif were you able to figure it out? Having a similar issue. |
@montrealist Btw, I tried '--net host' in Debian linux, it works. |
With Docker-CE, is this still the case? |
AFAIK, yes |
|
I am facing the same issue |
Replying "me 2" like some AOLer isn't helping the discussion, in fact, it's a great way to get the conversation locked. If you are just here to say "pl0x fix kthx1" All you have to do is click the "Subscribe" button in the right-hand column and click the "Thumbs Up" icon on the first post or the "Sad Face" emoji three posts above. |
One particular scenario that I'm trying to utilize this for (maybe there's another solution?) is to debug a node application with chrome devtools by passing in the Debugging via devtools is still considered an experimental feature in both node and chrome devtools so it's possible a bug exists in one of those places. However, when running the service locally (outside of the docker container) the debugger can connect just fine. Inside the docker container, chrome devtools never connects to the node websocket. If I tell the node process to bind to port 0.0.0.0 it appears to connect but no information is actually shared (no source code, console logs, or breakpoints). By default node inspect + chrome-devtools attempts to use 127.0.0.1 and my guess is that the issue is due to the way networking is set up between docker4mac and the host machine. Would love to see this working as I assume it would cause my use case to "just work". |
Hi there, "host" network mode should work on docker for mac if you disable the dns_search method by adding the command The explanation: By default, the container will try to resolve ip-addresses depending on the dns configuration of the host. Usually the host will have a google dns server specified to resolve addresses. The google dns server will however not be able to resolve internal localhost addresses. If you disable the external dns server with the dns_search setting, the internal addresses should be resolved correctly. |
@tikiatua it's still not working on me. I added following to docker-compose.yml:
or
Did you mean something else? |
This is outside of Compose's purview. People interested in a resolution to this issue should follow docker/for-mac#1031 instead. |
Same issue too. |
Does this work on Windows? |
If you just want to reach a service on the host from within a docker container on Mac OS X you cannot use
|
Same issue, solved by below, not sure if buggy or not.
|
Docker seems to like to change their |
Same issue, solved by below:
|
Same issue too. in MacOS 14.5 |
Hi, actually I want to deploy all my applications in one machine and I use "network_mode: host" for sharing the same network of host machine inside docker container.
But I find that I can't access my application with "localhost" in the host machine.
example :
Inside docker container, this command works well, but not work in the host machine
curl -H "Content-Type: application/json" http://localhost:8761/eureka/apps
ifconfig
in the container (IP is 192.168.65.2) :ifconfig
in the host machine (IP is 192.168.1.99) :I'm a little confused, IP inside container and host machine should not be the same in network_mode: host ?
Between the docker containers, they can share network (the two containers of my docker-compose.yml can communicate well between them with localhost) , but not with the host machine.
I think maybe I misunderstand the network_mode host.
The docker-compose.yml looks like :
Docker inspect (network part) :
Docker/Docker compose version:
Thanks in advance
The text was updated successfully, but these errors were encountered: