Reputation: 38777
In docker-compose you can specify ports like 1234
in order to publish it on an ephemeral port, and like 127.0.0.1:1234:1234
to publish it on a specific interface.
However, is there a way to use an ephemeral port on a specific interface?
There appears to be no --ip
option to docker-compose up
like there is for docker run
.
Upvotes: 1
Views: 1001
Reputation: 11940
Unless i am mistaken I assume you want to publish on a specific interface with ephemeral port - in a random way - you can use this in your docker-compose.yml
ports:
- "127.0.0.1::1234"
Or if you don't need to specify an interface and just want an ephemeral port you can use this:
ports:
- "1234"
In both scenarios this makes the container listen on a random port mapped to a specific port (e.g. 1234
) inside the container similar to what -P
would do in docker run
To set an ip for container in docker-compose you can use the following to make it work similar to --ip
in docker run
, assuming you have a custom network called my_network
networks:
my_network:
ipv4_address: 172.20.1.5
Upvotes: 3