Skip to main content

Container services

A container service runs your code: either an image AppHaven builds from your repository, or a prebuilt image it pulls from a registry.

services:
web:
type: container
image: ghcr.io/example/app:latest # or use `build` (below) instead
build: # build from source instead of pulling an image
dockerfile: Dockerfile # optional, default "Dockerfile"
context: . # optional, default repo root "."
args: # optional, docker build args
KEY: value
ports: # optional, list of ints, 1–65535
- 3000
env: # optional, map of string -> string
KEY: value
volumes: # optional, list of mounts
- name: <volume_name>
mount_path: /abs/path
healthcheck: # optional, lets other services wait for "healthy"
test: ["CMD-SHELL", "curl -fsS http://localhost:3000/ || exit 1"]
interval: 10s
depends_on: # optional, start ordering
- service: db
condition: healthy
FieldTypeRequiredRules
imagestringconditionalRequired unless build is set. Any image reference that can be pulled.
buildobjectconditionalBuild from source; see below. A container service declares image or build.
portslist of intnoPorts your service listens on. Each must be in the range 1–65535. See Networking.
envmap<string, string>noEnvironment variables for the container. See Environment variables.
volumeslist of {name, mount_path}noStorage mounts. See Volumes.
healthcheckobjectnoSee Healthchecks.
depends_onlist of {service, condition}noStart ordering. See Start order.

Building from source (build)

Give a service a build block and AppHaven builds its image from your repository on every deploy, at the exact commit you deploy. No registry or build pipeline needed. The build log appears in the console's Builds tab.

FieldTypeRequiredRules
dockerfilestringnoPath to the Dockerfile, relative to context. Default Dockerfile.
contextstringnoBuild context directory, relative to the repo root. Default ..
argsmap<string, string>noDocker build args.

A monorepo can build several services from one repository by giving each its own context:

services:
api:
type: container
build:
context: api
ports:
- 8080
frontend:
type: container
build:
context: frontend
ports:
- 3000

If a service sets both build and image, the image name is applied to the build result.

Healthchecks

A container service may declare a healthcheck, so other services can wait for it with depends_on: condition: healthy and the platform can report its readiness.

healthcheck:
test: ["CMD-SHELL", "curl -fsS http://localhost:3000/ || exit 1"]
interval: 10s
timeout: 3s
retries: 5
start_period: 20s
FieldTypeRequiredRules
testlist of stringyes["CMD", ...] (exec form) or ["CMD-SHELL", "<shell command>"]. The command runs inside your container.
intervaldurationnoTime between checks. Default 10s. Between 1s and 5m.
timeoutdurationnoPer-check timeout. Default 3s. Between 1s and 5m.
retriesintnoConsecutive failures before the service counts as unhealthy. Default 3. Between 1 and 20.
start_perioddurationnoGrace period before failures count. Default 0s. Up to 5m.

A duration is a positive whole number followed by s or m, for example 10s or 5m (start_period also accepts 0s).

Where to go next