There’s two approaches:
- Use a primary build container and a secondary PostgreSQL container (your current approach)
- Install PostgreSQL server in your build container from the distro repo
Either is good really, and what you’ll prefer probably comes down to what is fastest. I’d wager there is not much in it.
If you are happy to go for the second option, then installing the database server on the build container will give you everything you need to connect. You then just need to install php-pgsql. I have shown how to do something similar with MySQL here.