Most apps are one container, and for those Yard writes the compose file for you. But sometimes an app wants company: a background worker, a database, a little sidecar. Then you write the compose file yourself, and Yard runs it as it is.
If you have written a compose.yml before, this chapter is short. There is a contract of four lines, and one rule about the address your app listens on.
The file Yard writes for you#
Start by looking at what you get without a compose file. Yard keeps two files: app.compose.yml is the base every app gets, and build.compose.yml is an overlay that adds the build for the kinds Yard builds itself. Together they look like this, slightly trimmed:
# app.compose.yml — every appservices: app: image: ${IMAGE} restart: always networks: yard: aliases: [${PROJECT_NAME}] volumes: - ${DATA_DIR}:/data env_file: - ${APP_ENV} environment: PROJECT_NAME: ${PROJECT_NAME} PROJECT_DATA_DIR: /data SHA: ${SHA}networks: yard: external: true name: yard# build.compose.yml — only for an app Yard buildsservices: app: build: context: ${CHECKOUT} dockerfile: ${DOCKERFILE} pull_policy: never environment: PORT: "8000" STARIO_HOST: 0.0.0.0 STARIO_PORT: "8000" STARIO_TRACER: json expose: ["8000"]Everything in ${…} is filled in by Yard before Compose runs:
CHECKOUTis Yard’s clone of your repo.IMAGEis the tag for this deploy,localhost/<name>:<sha12>(plus-<tpl8>when Yard wrote the Containerfile).SHAis the full commit. For an image app it is the digest, and for a compose URL app thesha256:of the file.DATA_DIRis/srv/yard/apps/<name>/dataon the host.APP_ENVis the app’s env file, the oneyard env setwrites.PROJECT_NAMEis the app’s name.DOCKERFILEis the app’s Containerfile: a path in the repo, or the absolute path of the one Yard wrote.
The full files are ops/apply/app.compose.yml and ops/apply/build.compose.yml in the Yard repo. An image app runs app.compose.yml alone: no build and no PORT, so the image listens where its publisher made it listen.
The contract#
Put a compose.yml (or compose.yaml) at the repo root or in ops/, and a deploy on auto picks it instead of Yard’s pair. A file with another name or in another place works too: name it with yard app set --runs deploy/stack.yml. What an app runs explains the runs value.
Four lines in the compose file matter:
Service
appon networkyard. This one is required, and the deploy fails without it. Caddy dials<name>-app-1, and it can only reach containers onyard.image: ${IMAGE}andbuild.context: ${CHECKOUT}on the service that builds. That is how the image gets its commit tag, and how a revert finds the old one.env_file: [${APP_ENV}]. Without it,yard env sethas no effect. The deploy log warns.${DATA_DIR}:/dataundervolumes:. Without it, the app has no safe place for files. The deploy log warns.
Yard does not merge your file with its own. So the variables that Yard’s files set are yours to set. One of them is not optional: the app must still listen on 0.0.0.0:8000. Yard’s files set STARIO_HOST, STARIO_PORT, and PORT for that. A Stario app in your own compose file needs STARIO_HOST: 0.0.0.0 and STARIO_PORT: "8000", or it listens on 127.0.0.1, and Caddy answers 502. Add PROJECT_DATA_DIR and SHA too, if your app reads them.
Example: an app and a worker#
Two processes, one image:
services: app: build: context: ${CHECKOUT} image: ${IMAGE} pull_policy: never restart: always networks: [yard] env_file: [${APP_ENV}] volumes: ["${DATA_DIR}:/data"] environment: STARIO_HOST: 0.0.0.0 STARIO_PORT: "8000" PROJECT_DATA_DIR: /data SHA: ${SHA} worker: image: ${IMAGE} pull_policy: never restart: always command: ["python", "-m", "myapp.worker"] env_file: [${APP_ENV}] volumes: ["${DATA_DIR}:/data"] environment: PROJECT_DATA_DIR: /data networks: yard: external: true name: yardOnly app has a build: section, so the image is built once and both services run it. The worker is not on yard, because nothing needs to reach it from outside.
Example: a database next to the app#
services: app: build: context: ${CHECKOUT} image: ${IMAGE} pull_policy: never restart: always networks: [yard, default] env_file: [${APP_ENV}] environment: STARIO_HOST: 0.0.0.0 STARIO_PORT: "8000" db: image: docker.io/library/postgres:17 restart: always env_file: [${APP_ENV}] environment: POSTGRES_USER: app volumes: ["${DATA_DIR}/postgres:/var/lib/postgresql/data"] networks: yard: external: true name: yardLook at the networks. app is on two: yard, so Caddy can reach it, and default, the project’s private network, so it can reach db. The database is only on default.
The password is not in the file. Both services read the env file, so set it there, once:
yard env set POSTGRES_PASSWORD=… DATABASE_URL=postgresql://app:…@db/appWarning. Every container on yard can reach every other container on yard, across all apps. Keep databases and internal services off it. Put them on the project’s default network, which only that app’s containers share.
The database files go under ${DATA_DIR}, so they survive deploys like any other app data.
Healthchecks#
Give the app service a healthcheck. With one, a deploy waits until the new container is healthy, and the old version comes back when it never is. In a compose file, it looks like this:
services: app: # … healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/')"] interval: 10s timeout: 3s start_period: 30sA HEALTHCHECK line in the Containerfile works too. Keep the interval short: a long one makes every deploy time out and revert. Healthchecks explains what the check does during a swap, and why the interval matters so much.
Any language, any server#
Yard never looks inside your image. It builds what the repo describes, starts it, and waits for healthy. So a Go service, a Node app, or nginx serving a static site deploys exactly like a Stario app, as long as it keeps the contract.
A repo that already runs with docker compose somewhere else usually needs three changes to move in: name the web service app, add the yard network, and attach env_file: [${APP_ENV}].
By the way#
Yard runs
docker-composeagainst Podman’s Docker-compatible API. So the Compose you know is the Compose you get, includingdepends_on,profiles, andcommand.--remove-orphansis on. Delete a service from the file, and the next deploy removes its container.A compose file at a URL is a compose file like these, for a service that needs no repo of yours. What an app runs covers it.
Each deploy builds with
docker-compose buildwhen the repo has its own compose file, and with a quickerpodman-remote build --format dockerfor Yard’s files. Both produce Docker-format images.