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" prevents port binding #3442
Comments
Thanks @shin-; I actually did come across that (very helpful!) set of articles while trying to work around this, but I sort of hit a hiccup when reaching the That been said, are there any good practices/concerns when using |
Hey, sorry for the late response. |
Thanks again @shin- The only way I could work around this is by manually injecting host's IP into the containers and referencing it from them that way. I've now been able to successfully containerise the app, so I can just use the alias hostname and it works, although I find it weird that this still works the way it does. I'm not sure if it's of any use discussing this further, since I know the complete docker network stack is supposed to be revamped in the near future. You may close this if you like; thanks for your help! |
Glad you were able to work it out. As for discussion of the networking stack in Docker, the docker repo is probably a better avenue to do so. |
Hi, I've been trying, to no avail, to make work the following development scenario with
docker-compose
:Environment:
1.11.1, build 5604cbe
docker-compose version 1.7.1, build 0a9ab35
docker-py version: 1.8.1
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1j 15 Oct 2014
app
: web application, running natively on host.db
).worker
: headless application, running on a container.db
)app
) REST APIdb
: database, running on a containerSince
app
isn't a container, I need to exposedb
's port to the host machine, so I can access the db container from it.Here's what a simplified version of my
docker-compose.yml
file looks like:docker-compose up
works properly and then I run myapp
separately, with its DB connection string tolocalhost:27017
.app
andworker
can accessdb
, no problem; the issue appears whenworker
wants to hitapp
's API: I can't reach the host machine by default.Still, my DB logs do list that it is receiving connections from
172.18.0.1
so I thought that should be the IP for my host machine from the default docker network created by compose.When attaching to the container and trying to
curl http://172.18.0.1:8080
, though, I got no answer. Still, when checkingifconfig
I didn't even see thedocker0
interface, justeth0
andlo
.Since I'm new to the networking layer of compose, I went through all the docs I could find and tried several things:
My networks are:
So I thought maybe using the default bridge network instead of the one created by
docker-compose
might shed some light. So I addednetwork_mode: bridge
to both services indocker-compose.yml
:This didn't produce any change except that the
docker0
interface became visible from within the containers and that the IP reporter by the database was now172.17.0.1
instead of172.18.0.1
; still no answer from the gateway IP in that network.Finally, I tried making all services hook directly to the host network with
network_mode: host
. Also, I had to specify the connection string for the DB manually since container linking isn't allowed with this network mode:And here's the weird part:
app
now is unable to reach thedb
container.docker ps
yields that no port is available for thedb
container, even thoughports
is specified there:And here's where I don't know how to move forward. Is this the expected behavior?
My workaround for this is to manually specify my host's local IP through
environment
to the worker and using that IP from inside the app. But that breaks whenever I switch networks or if I try to run this scenario on a different machine. Is there any other "proper" way around this?Thanks in advance.
FWIW, my
docker info
output:The text was updated successfully, but these errors were encountered: