I had this problem too -
pg_dump: error: server version: 14.5 (Ubuntu 14.5-2.pgdg20.04+2); pg_dump version: 13.8 (Debian 13.8-0+deb11u1)
pg_dump: error: aborting because of server version mismatch
I just added postgres-client v14 to my Dockerfile and all OK
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(sed -n 's/VERSION_CODENAME=\(.*\)$/\1/p' /etc/os-release)-pgdg main" 14 > /etc/apt/sources.list.d/pgdg.list
ARG DEPLOY_PACKAGES="file vim curl gzip nodejs postgresql-client-14"