I use docker-machine and docker-compose.
The docker machine I use has multiple interfaces.
Is there a way to force services to listen only on a specific interface of the machine without defining the ip address of this interface in the port section?
Right now I use this in docker-compose.yml
ports:
- "10.5.1.28:80:80"
- "10.5.1.28:2222:22"
- "10.5.1.28:443:443"
But it is not very convenient as I have to rewrite all ips in case of change.
Is there any simplier way to do this?
One elegant solution is to create external network.
For example with two nginx using external networks (internet & intranet):
Services definition:
nginx1:
build: ./nginx
ports:
- "80:80"
networks:
- intranet
nginx2:
build: ./nginx
ports:
- "80:80"
networks:
- internet
Network definition:
networks:
internet:
external: true
intranet:
external: true
Then prior first docker-compose up you will have to create the external network
In this example 192.168.178.69 is the ip on the internet side and 10.5.1.22 on the intranet side
docker network create -d bridge -o \
com.docker.network.bridge.host_binding_ipv4=192.168.178.69 internet
docker network create -d bridge -o \
com.docker.network.bridge.host_binding_ipv4=10.5.1.22 intranet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With