#!/usr/bin/env bash # UFW: allow Docker bridges → host Postgres only (not public internet). set -euo pipefail cd ~/games_app sudo ufw allow from 172.16.0.0/12 to any port 5432 proto tcp comment 'Docker to Postgres' sudo ufw allow from 192.168.0.0/16 to any port 5432 proto tcp comment 'Docker bridge alt' # Also accept on docker bridges by interface (covers hairpin edge cases) sudo ufw allow in on docker0 to any port 5432 proto tcp comment 'docker0 to PG' || true sudo ufw status numbered | head -40 PGPASS=$(python3 - <<'PY' import re from pathlib import Path m=re.search(r'^POSTGRES_PASSWORD=(.*)$', Path('.env').read_text(), re.M) print(m.group(1).strip() if m else '') PY ) export PGPASSWORD="$PGPASS" echo "Docker→PG test:" sudo docker run --rm --add-host=host.docker.internal:host-gateway \ -e PGPASSWORD="$PGPASS" postgres:16-alpine \ psql -h host.docker.internal -U postgres -d games_platform_db -c 'SELECT 1 AS docker_ok;' echo "DOCKER_PG_OK"