Connect my php5 + apache container to my server database through public ip

hello I have an application developed in php 5 + postgres on a ubuntu 15 server, I am planning to update my ubuntu to 18.04, that is why I created a php5 + apache container for my application, my question is, by hosting my application in the container this normally you can connect to the postgres database through the public ip being on the same server where it is hosted?

I have this volume

volumes:
- / var / www / html / nameapp /: / var / www / html /