Had the same issue. At first i thought it may be because of a wrong port mapping. I double checked it and it was fine.
Then i realized I was using a custom postgres.conf file. There I forgot to add:
listen_addresses = '*'
After adding it and restarted the container. Everything was fine :)