Reputation: 152
I've googled this to death.
I want one container bound to one host IP/port, the other container on a different one, for various reasons.
I have (snipped out some info)
container1:
network_mode:
host ports:
- 192.168.1.224:80:80
container2:
network_mode:
host ports:
- 192.168.1.225:80:80
Docker actually starts up, but when I visit each IP in the browser, both URL's will return container1's stuff.
Has anyone done this? All I can find online is mostly related to docker and not docker-compose (starting docker with some arguments), or people arguing it should be done another way.
Upvotes: 0
Views: 791
Reputation: 159373
Delete the network_mode: host
setting: it's getting in your way here.
Specifying network_mode: host
bypasses all of Docker's normal networking setup. The ports:
setting has no effect. Each process here sees both of your host interfaces, and presumably tries to bind to both of them. If you use the default network_mode: bridge
, each container gets an isolated network stack, and you can use ports:
as you've done to selectively expose containers to specific interfaces.
network_mode: host
is really only appropriate in a couple of specific cases; only if your server process is listening on thousands of ports, or its specific port is unpredictable, or if you have an actual need to inspect the host's network setup but can't run your process directly on the host.
Upvotes: 2