Milad Rahimi
Milad Rahimi

Reputation: 3834

docker-compose expose on a random port when no variable is set in env

I want docker-compose to:

I've tried this but it always exposes a random port.

ports:
      - 80

I've tried this but it always exposes on 80 when there is no value in env.

ports:
      - ${PORT:-80}

What I like to achieve could be something like this:

ports:
      - ${PORT:-RANDOM}

Upvotes: 0

Views: 353

Answers (1)

Daniel Finch
Daniel Finch

Reputation: 443

Setting the default to 0 will cause the operating system to assign a random port.

For example:

ports:
      - ${APP_PORT:-0}:80

Upvotes: 1

Related Questions