Several services with compose
untainer up starts the services of a compose file in one VM, in the order their depends_on and readiness ask for.
untainer up starts the services of a compose file, each in its container of one VM, in the
order their depends_on and readiness ask for. examples/compose is a Node API that reads from
Postgres:
compose.yaml
# A Node API that reads and writes notes in Postgres: `untainer up` in this directory.
name: notes
services:
api:
image: node:24-alpine
command: [node, /app/server.mjs]
environment:
PGHOST: db
ports: ['3000:3000']
volumes: ['./api:/app:ro']
depends_on: [db]
db:
image: postgres:17-alpine
environment:
POSTGRES_HOST_AUTH_METHOD: trust
volumes: ['pgdata:/var/lib/postgresql/data']
volumes:
pgdata:untainer up # Ctrl-C stops every service
curl localhost:3000/- One network: the services share the VM's network;
apireaches Postgres asdb. - Order:
apistarts oncedbis ready (its image's probe passed), not merely started. - Ports (
3000:3000) are published on the host's 127.0.0.1. - Volumes: a path is a directory of the host (relative to the compose file); a named volume is
a directory under
~/.cache/untainer/volumes/<project>/, so the data outlivesup. - Keys untainer does not support (
build,healthcheck,restart,networks...) are named in a warning, not silently dropped.
The same from code, with the images built into dist/ and the API's code in ./api:
up.ts
import { createRuntime, hostVolume, loadImage } from 'untainer';
const rt = await createRuntime({
images: [await loadImage('./dist/postgres-17-alpine'), await loadImage('./dist/node-24-alpine')],
});
const { api } = await rt.up({
db: { image: 'postgres', env: { POSTGRES_HOST_AUTH_METHOD: 'trust' } },
api: {
image: 'node',
cmd: ['node', '/app/server.mjs'],
env: { PGHOST: 'db' },
volumes: { '/app': hostVolume('./api', { readOnly: true }) },
dependsOn: ['db'],
},
});
await api.ready({ probe: 'http:3000/' });
console.log(await (await api.fetch('/', { port: 3000 })).json()); // { postgres: 'PostgreSQL 17...
await rt.shutdown();examples/compose/test.ts runs it twice and checks that a note written in the first run is still
there in the second.