Yes, you can reference containers by their service names, no numeric extension should be added, the name should be exactly as it is defined in docker-compose.yml.
port option is for just exposing the container port to your host, the option port: "5432" will expose port 5432 from the container on your host on 5432.
I would recommend checking that your host 5432 port is free, otherwise map to a different port:
ports:
- "5432:5433"
Also ensure that you are not connecting to some already exsting volumes with some strange Postgres configurations, a clean postgres/postgis container will always serve on port 5432 by default.
The last and the first thing I should have mentioned is to check that the database container has started as expected, it can happen that it will not start if it’s missing some mandatory configuration options (like username), you should have logs that it started accepting clients on port 5432.


















