Docker Compose PostgreSQL Generator
Generate a production-shaped docker-compose.yml for PostgreSQL in seconds. Choose the official image, pgvector, PostGIS or TimescaleDB, set credentials and a published port, and get compose YAML with a named volume, a pg_isready healthcheck, an optional init script and an optional pgAdmin service. Everything runs in your browser — no data is uploaded.
- Scripts in ./initdb only run on first start, when the data volume is empty. Run `docker compose down -v` to re-trigger them.
Save the YAML as docker-compose.yml, then run docker compose up -d. Check readiness with docker compose ps and open a shell with docker compose exec db psql -U app -d app.
Do more than docker compose postgresql generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Pick your PostgreSQL major version and image variant.
- Set the database name, user, password and the host port you want to publish.
- Turn on healthchecks, init scripts or pgAdmin as needed, then copy the generated docker-compose.yml.
Frequently asked questions
Why should I use a named volume instead of a bind mount for Postgres data?
A named volume is managed by Docker and keeps the correct ownership and permissions for the postgres user inside the container. Bind mounts to a host directory frequently break on macOS and Windows because the host filesystem does not support the ownership and fsync semantics Postgres expects, which can cause initdb to fail or risk data corruption. Use a named volume for the data directory, and bind mounts only for read-only things like init scripts.
Why does my init script not run?
Scripts placed in /docker-entrypoint-initdb.d only execute the first time the container starts with an empty data directory. If the named volume already contains a database, the entrypoint skips them entirely. Run `docker compose down -v` to delete the volume and start fresh, or apply the change as a normal migration instead.
How do other containers connect to this Postgres service?
Inside the compose network, containers reach Postgres at the service name on port 5432 — for example postgres://app:password@db:5432/app — regardless of which host port you published. The published port only matters for tools running on your host machine. Chat2DB, a free AI SQL client for Windows, macOS and Linux, connects to the published port and lets you browse the schema and write SQL in plain language.
