29. Postgres and the emulator in one pod
29. Postgres and the Spanner emulator as services in one pod¶
Learning goal: whether transpire's two services, postgres:18 and the
Spanner emulator, start side by side in one gVisor pod as services, under
their images' own users, with Postgres's data directory writable, and
whether the job's container reaches them by name (design, 'Readiness',
'Names', 'Volumes and pads').
Method: spike/compose_pod/main.go services, through containerd's CRI
with handler runsc, on smaug and in the Mac runner's Lima VM (the hosts of
experiment 27). One pod, the hosts file of experiment 27 naming
localhost, the pod's hostname, postgres and spanner-emulator, mounted
at /etc/hosts in every container. Containers, started in this order:
postgres:docker.io/library/postgres:18, its own entrypoint and user,POSTGRES_PASSWORDset;spanner-emulator:gcr.io/cloud-spanner-emulator/emulator:1.5.56, its own entrypoint and user;main:postgres:18again, as uid 1000 (the job's container runs as the runner's uid, which no image names), runningpg_isready -h postgres -U postgresin a loop, then opening TCP connections tospanner-emulator:9010and:9020with bash's/dev/tcp.
Meanwhile the probe runs pg_isready -U postgres in the postgres
container through ExecSync once a second until it exits 0. Transpire's
own scripts-test was not run; main stands in for it.
No predictions were written down before the run.
Results (2026-11-30)¶
| smaug (amd64) | Mac VM (arm64) | |
|---|---|---|
| All three containers start and stay running | yes | yes |
pg_isready by ExecSync in postgres |
exit 2 (no response) four times, exit 1 (rejecting connections) once, then exit 0, 5.6 s after its container was created (images cached) |
exit 0 on the first call, 12.0 s after creation (the emulator's image was pulled in between) |
main reaches postgres:5432 by name |
yes | yes |
main reaches spanner-emulator:9010 and :9020 by name |
yes | yes |
Users, from ps in the pod |
postgres (after the entrypoint's switch from root), the emulator's gateway_main and emulator_main as root, main as 1000 |
the same |
/var/lib/postgresql (the image's VOLUME) |
drwxrwxrwt postgres postgres, initdb wrote 18/docker in it, writable |
the same; a later run kept with the pod up showed it is a bind mount of a directory containerd made, below |
psql -c 'select version()' |
PostgreSQL 18.7 ... x86_64 |
PostgreSQL 18.7 ... aarch64 |
ExecSync of id or /bin/sh -c true in the emulator |
fails: the image has neither (gRPC Unknown, failed to load /bin/sh: no such file or directory) |
the same |
pg_isready -h postgres in main, without -U |
exit 3, no attempt |
the same |
What we learned¶
- The two services share a pod under runsc on both architectures, each as its image's own user, and the job's container reaches both by name through the hosts file.
ExecSyncofpg_isreadyin Postgres's container tracks Postgres's start-up exactly: no response while initdb runs, rejecting while the server starts, then accepting. Correction (2026-12-01): only over TCP. The check here used the unix socket, which the image's temporary init server also answers on, withlisten_addresses=''. A job that connected by name in that window was refused (TestComposeServicesIntegrationon smaug);pg_isready -h localhostpasses only once the real server listens on TCP.- The image's data path is writable, and it is not in the container's
root filesystem. containerd's CRI gives every path an image declares as a
VOLUMEa directory of its own on the host,/var/lib/containerd/io.containerd.grpc.v1.cri/containers/<id>/volumes/<hash>, bind-mounted read-write (seen in the Mac VM, 2026-11-30, from the container's spec): Postgres's data (40 MB after initdb,18/dockerowned by uid 999 on the host) lives there, on the host's disk, and containerd removed the directory with the pod. A per-run volume at a path the image declares as aVOLUMEis therefore on disk already; one at any other path is in the root filesystem's overlay (experiment 30). - The emulator's image has no shell and no tools, so no healthcheck can run inside it; that is the case the design already sends back to the repo (transpire's health sidecar).
- libpq refuses to try without a user name for an unnamed uid. In the
job's container, which runs as a uid no
/etc/passwdnames,pg_isreadyandpsqlneed-UorPGUSER; without one they exit 3,no attempt, before any connection.
What it changes¶
- The design's single pod of services stands for transpire's check.
- A job whose container uses libpq with no user set fails in a way that
looks like a network fault. The job's docs (or its error message, if the
runner can see it) should say that the job runs as an unnamed uid and
needs
PGUSER.