How do I write Dockerfile for PHP image and PostgreSQL driver

How do I write Dockerfile for PHP image and PostgreSQL driver?

I wrote a Dockerfile but it threw an error.

My Dockerfile (I refer to https://gist.github.com/ben-albon/3c33628662dcd4120bf4)

FROM php:8.2-apache-buster

RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql

COPY . /var/www/html

My docker-compose.yml (There is a separate PostgreSQL’s docker-compose.yml)

version: "3"

services:
  php:
    build: .
    ports:
      - 9999:80

The error

Fatal error: Uncaught Error: Call to undefined function pg_connect() in /var/www/html/db.php:7 Stack trace: #0 /var/www/html/inc/header.php(2): require_once() #1 /var/www/html/index.php(14): require_once(‘/var/www/html/i…’) #2 {main} thrown in /var/www/html/db.php on line 7