Blueprints · Docker & Databases
Production
15 min · Docker
PgBouncer on localhost
Publishes PgBouncer on 127.0.0.1. The upstream Postgres URL in the file points at the host loopback. Replace change-me before you start it.
Why this should not be public
PgBouncer passes logins through to Postgres, so a public PgBouncer is a public database with one extra hop.
Live config
Baked-in protections
- The host port is 127.0.0.1
- change-me blocks the start script
- The container cannot gain new privileges
Step 1 · yaml
Compose file
/opt/pgbouncer-loopback/compose.yaml
Written under the compose directory. It is not started. The image tag is the release this blueprint was checked with: look at the project's release notes and use the newest patched tag.
services:
app:
image: edoburu/pgbouncer:1.22.1-p0
ports:
- "127.0.0.1:6432:5432"
environment:
DATABASE_URL: postgres://app:[email protected]:5432/app
security_opt:
- no-new-privileges:true
restart: unless-stopped
Step 2 · bash
Start script
/opt/pgbouncer-loopback/up.sh
Review the image tag and the password, then run this yourself.
#!/bin/sh set -eu cd "/opt/pgbouncer-loopback" if grep -q 'change-me' compose.yaml; then echo "Replace change-me before starting." exit 1 fi docker compose up -d
Step 3 · bash
Read-only check
/root/portgate-blueprints/pgbouncer-loopback-check.sh
Prints status. It does not change the service.
#!/bin/sh
set -eu
if command -v docker >/dev/null 2>&1; then
docker ps --format '{{.Names}} {{.Ports}}' || echo "Docker is installed but the daemon did not answer."
else
echo "Docker is not installed. The compose file is staged only."
fi