| 1 | # Docker PostgreSQL Example |
| 2 | |
| 3 | This example provisions PostgreSQL 18 Alpine with Docker resources: |
| 4 | |
| 5 | - `Docker.RemoteImage` pulls `postgres:18-alpine` |
| 6 | - `Docker.Network` creates an app network |
| 7 | - `Docker.Volume` creates persistent database storage |
| 8 | - `Docker.Container` starts PostgreSQL with a redacted password, a network alias, a named volume, and a host port |
| 9 | - `Docker.inspectContainer` returns the bound host port |
| 10 | |
| 11 | Docker resources use the active Docker CLI context. That can be Docker Desktop, a remote Docker host, an SSH context, or a CI runner daemon. |
| 12 | |
| 13 | These resources are separate from `Cloudflare.Container`. The bridge between Docker and cloud container platforms is an image reference or registry digest, not a swappable container object. |
| 14 | |
| 15 | ## Commands |
| 16 | |
| 17 | ```sh |
| 18 | bun install |
| 19 | POSTGRES_PASSWORD=change-me bun run --filter docker-postgres-example deploy |
| 20 | bun run --filter docker-postgres-example destroy |
| 21 | ``` |
| 22 | |
| 23 | If `POSTGRES_PASSWORD` is omitted, the example generates and stores a redacted password with `Alchemy.makeRandom`. |
| 24 | |
| 25 | The stack publishes PostgreSQL on `localhost:15432`: |
| 26 | |
| 27 | ```sh |
| 28 | psql postgres://alchemy:change-me@localhost:15432/app |
| 29 | ``` |