How to connect to a PostgreSQL database running in Docker
Connect a GUI to PostgreSQL running in a Docker container — find the published port, build the connection string, and browse your data. A short, practical guide.
A PostgreSQL container is not special to connect to — it is just a host and a port. The only trick is making sure the port is published to your machine, then pointing a client at it. Here is the whole path.
1. Publish the port
When you run the container, map the container's 5432 to a port on your host with -p:
docker run --name pg -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postgres
The -p 5432:5432 is the important part — it exposes Postgres on localhost:5432. If 5432 is already taken on your machine, publish a different host port, e.g. -p 5433:5432, and use 5433 below.
Using Docker Compose, the equivalent is:
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: secret
ports:
- "5432:5432"
2. Build the connection string
Point your client at the host port you published:
postgresql://postgres:secret@localhost:5432/postgres
- host
localhost(the container is reachable on your machine's loopback) - port whatever you published on the host side of
-p - user / password from the container's environment
- database
postgresby default, or whatever you created
3. Connect
In JustDB, paste that connection string and connect. There is nothing Docker-specific to configure — a container is just another host and port. Once connected, browse tables, run SQL and edit rows like any other database.
If it won't connect
- Container not running? Check
docker ps— it should list the container with the port mapping. - Port not published? A container without
-pis only reachable from inside Docker's network, not from your host. Add the mapping and restart it. - Port clash? If another Postgres already owns 5432, publish on a different host port and use that in the connection string.
Why JustDB for this
- No Docker-specific setup — point it at
localhostand the published port. - Local, Docker or hosted Postgres over TLS, all the same way.
- Free, native, no signup on macOS and Windows.