mdmb
mdmb

Reputation: 5283

docker-compose - env vars based on the ports

So I have 2 services running - my website and the API.

In my code for the website I specified that it should use the API that has port equal to API_PORT env var.

My question: is there a way to set the API_PORT variables based on the ports from api service?

Overview of my docker-compose.yml:

api-service:
    ...otherconfig
    ports:
      - 8009:8009
website:
    ...

Upvotes: 2

Views: 399

Answers (1)

omu_negru
omu_negru

Reputation: 4770

Just inject the API_PORT env var into your compose file too:

export API_PORT=8009

then in the compose file

api-service:
    ...otherconfig
    ports:
      - ${API_PORT}:${API_PORT}
website:
    ...

Upvotes: 3

Related Questions