Connect to Postgres database in Docker container
26 May 2022 (Updated 26 May 2022)
Suppose you’re using Docker Compose and you’ve configured Postgres to run as one of your services. Perhaps with a docker-compose.yml
file like this:
version: '3'
services:
database:
image: postgres:${POSTGRES_VERSION:-13}-alpine
ports:
- "5432"
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe}
POSTGRES_USER: ${POSTGRES_USER:-symfony}
volumes:
- db-data:/var/lib/postgresql/data:rw
volumes:
db-data:
Suppose you’ve started your services using docker-compose up -d
, ran docker-compose ps
and see the following containers:
NAME COMMAND SERVICE STATUS PORTS
guestbook-database-1 "docker-entrypoint.s…" database running 0.0.0.0:51961->5432/tcp
You should be able to connect to this Postgres database with the following TablePlus connection settings:
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment