Understanding docker-compose config

Hi guys,

Have some questions when configuring a Postgres db using docker-compose file:
image

“5432:5432”: what means the first and second number?

And if I also want to configure those with an env variable how can I do it, since this is a string?

Hi @Xavier.Vieira

The port syntax is "<host-port>:<container-port>"

This means that if your container was running a service that listens on port 8080, and the dockerfile for it is EXPOSE-ing 8080, but from the outside world you wanted to connect to the container using port 80 (e.g. http://localhost/) then the port specification would be "80:8080".

Second question, AFAIK it should interpolate the string…

    ports:
    - "${HOST_PORT:-5432}:5432"

Got it! Thank you for the clarification Alistair.