Rich McCluskey
Rich McCluskey

Reputation: 2011

What's the docker-compose equivalent for docker run --publish-all?

Docker provides the option --publish-all for docker run.

--publish-all , -P :        Publish all exposed ports to random ports

What would be the equivalent when using docker-compose? I've looked through the docker compose cli and yml file docs and can't find anything like that.

For context, I am looking to do this with Elasticsearch as recommended by their documentation for deploying to production. See #4 here.

The image exposes TCP ports 9200 and 9300. For clusters it is recommended to randomize the published ports with --publish-all, unless you are pinning one container per host.

Upvotes: 1

Views: 1700

Answers (1)

m0nhawk
m0nhawk

Reputation: 24178

There is no option like this available.

But this can be done with docker-compose.yaml configuration.

You can specify ports in the following format:

ports:
 - "9200"
 - "9300"

Then, on docker-compose up -d it will publish this ports to random host ports (from local test run):

~ ➜ docker-compose ps
       Name                     Command               State                        Ports
--------------------------------------------------------------------------------------------------------------
elasticsearch_test   /usr/local/bin/docker-entr ...   Up      0.0.0.0:32769->9200/tcp, 0.0.0.0:32768->9300/tcp

And you can query it like this:

~ ➜ curl -XGET 127.0.0.1:32769

Upvotes: 2

Related Questions