Here is my docker compose:
services:
test-db:
image: postgres:18.1
ports:
- "5433:5433"
volumes:
- pgdata-test:/var/lib/postgresql
environment:
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: password
command: -p 5433
volumes:
pgdata-test:
Logs from DB container confirm DB started on 7433.
test-db-1 | PostgreSQL init process complete; ready for start up.
test-db-1 |
test-db-1 | 2025-12-27 01:56:16.668 UTC [1] LOG: starting PostgreSQL 18.1 (Debian 18.1-1.pgdg13+2) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
test-db-1 | 2025-12-27 01:56:16.669 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 7433
test-db-1 | 2025-12-27 01:56:16.669 UTC [1] LOG: listening on IPv6 address "::", port 7433
test-db-1 | 2025-12-27 01:56:16.670 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.7433"
test-db-1 | 2025-12-27 01:56:16.672 UTC [71] LOG: database system was shut down at 2025-12-27 01:56:16 UTC
test-db-1 | 2025-12-27 01:56:16.674 UTC [1] LOG: database system is ready to accept connections
Docker ps shows port forwarded
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2c2a3b72886 postgres:18.1 "docker-entrypoint.s…" About a minute ago Up About a minute 5432/tcp, 0.0.0.0:7433->7433/tcp, [::]:7433->7433/tcp test-db-1
Trying to connect from the host:
❯ psql -h localhost -U test -d test -p 7433
psql: error: connection to server at "localhost" (::1), port 7433 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 7433 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
Now if I change the port to 5432, everything will work as expected.
Originally I was trying to run the DB on 5432 and only map the container port to 5433 but that didn't work either so I tried to also change the port postgresql binds to but nothing seems to work.
Here is my docker compose:
Logs from DB container confirm DB started on 7433.
Docker ps shows port forwarded
Trying to connect from the host:
Now if I change the port to 5432, everything will work as expected.
Originally I was trying to run the DB on 5432 and only map the container port to 5433 but that didn't work either so I tried to also change the port postgresql binds to but nothing seems to work.