Write the Compose File
Every PR preview runs your own Docker Compose file. This page explains what Helm provides, what your Compose file must provide, the settings Helm refuses and why, and gives a complete example for a Django backend with PostgreSQL, Redis and a Celery worker.
What you're about to do, in plain English
Docker Compose is a tool that starts several containers together from one file,
usually called docker-compose.yml. Each entry under services: is one
container: your app, its database, a cache, a background worker. A container is an
isolated, packaged copy of a program with everything it needs to run.
For each preview, Helm starts a new virtual machine, copies your backend repository into it, and runs your Compose file there. You describe the whole stack in that file, the way you would to run it on your own computer. Helm adds no services and changes none of yours, except for the limits, the route and the env file described below.
What Helm provides
- A virtual machine for each preview, which no other preview shares, on 64-bit x86 Linux (
linux/amd64). It is deleted when the preview is rebuilt or torn down. - Docker and Docker Compose, ready to use. Your commands can call
docker compose. - A copy of your repository, at the branch or commit the preview is for. Helm runs your Compose file from the folder it is in, so paths such as
build: .and./configare relative to that folder. - Your project's variables and secrets, from the Container Environment Variables card on the Preview Environments settings tab, in every container of your Compose file. Values that span several lines, such as a PEM private key, arrive whole. "How variables reach your preview" below explains how.
-
Two variables of its own, and only two:
PREVIEW_DOMAIN: the preview's domain, for exampletastyspread-pr-118-x7k2q9.preview.helmcode.dev.PREVIEW_URL: the preview's address, for examplehttps://tastyspread-pr-118-x7k2q9.preview.helmcode.dev.
They reach every container and your commands in the same way as your own variables, so your Compose file can use
${PREVIEW_DOMAIN}and${PREVIEW_URL}. You can rename them or turn them off; see Preview Variables. - The route to your web service. Helm sends the preview's address to the service named in the Web Service setting (
appunless you change it), on the App Port (8000unless you change it). Helm handles HTTPS, so your service receives plain HTTP. - Memory and processor limits. Helm applies the virtual machine's limits to every service in the file. See "Resources" below.
Helm sets nothing else. In particular it no longer sets DEBUG,
ALLOWED_HOSTS, SECRET_KEY, DATABASE_URL or
PORT, and it does not add a database. Your Compose file or your project's variables
set everything your app needs.
How variables reach your preview
- Every variable and secret you set in the portal, plus
PREVIEW_DOMAINandPREVIEW_URL, is placed in the environment of every container of your Compose file, including third-party images such aspostgresandredis. Helm does this by adding its own env file to every service, so your Compose file does not needenv_fileorenvironmententries for them. - A value written under
environment:in your Compose file wins over a portal value. To let the portal override a default, write it asNAME: ${NAME:-default}. - Avoid portal variable names that third-party images read (for example
POSTGRES_PASSWORD,POSTGRES_DB,REDIS_PASSWORD,PORT) unless you mean the value for those containers too. - The same variables are available to
${NAME}substitution in the Compose file and to the pre-deploy, start and first-deploy commands.
Helm's env file comes after any env_file: entries of your own, so a portal value
also replaces the same name in your repository's own env file. More detail is in
Preview Variables.
What your Compose file must provide
- Every service the preview needs, including the database, a cache such as Redis, and any background workers. A preview starts empty, so the database starts with no tables; create them with the Pre-deploy Command (see Preview Commands).
- A
build:section or animage:for the web service. Withbuild: .Helm builds the image from the Dockerfile in your repository. Animage:must be one Docker can download without logging in. - A web service that listens on all network interfaces (
0.0.0.0) at the App Port, and answersGET /with any status below 500. A redirect to a login page, a404or a400all count. Do not redirect plain HTTP to HTTPS; for Django, leaveSECURE_SSL_REDIRECToff in previews. - Images for 64-bit x86 Linux (
linux/amd64). An image that exists only for ARM, for example one built on an Apple Silicon Mac and pushed aslinux/arm64only, does not start. - A stack that starts within 20 minutes, including building the images and running the pre-deploy command.
Your Compose file does not need to mention Helm's env file. If it still has the line
env_file: /run/helm/preview.env from an earlier version of these pages, you can
delete it; it does no harm.
A complete example
This example is a Django project called myproject with PostgreSQL, Redis and a
Celery worker. The app image is built from the repository's own Dockerfile. Replace
myproject with your Django project's name.
The Dockerfile
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt gunicorn celery redis
COPY . .
# Collect static files once, at build time, so the preview starts sooner.
RUN SECRET_KEY=build-only python manage.py collectstatic --noinput
RUN useradd --uid 10001 app
USER app
EXPOSE 8000
CMD ["gunicorn", "myproject.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "2"]
The Compose file, docker-compose.yml
# Settings the app and the worker share. A key starting with x- is ignored
# by Docker Compose and only used for the <<: *app lines below.
x-app: &app
build: .
# Helm places the project's variables and secrets, PREVIEW_DOMAIN and
# PREVIEW_URL in every container, so no env_file line is needed for them.
environment:
DEBUG: "True"
ALLOWED_HOSTS: ${PREVIEW_DOMAIN},localhost
CSRF_TRUSTED_ORIGINS: ${PREVIEW_URL}
CORS_ALLOWED_ORIGINS: ${PREVIEW_URL}
SERVER_BASE_URL: ${PREVIEW_URL}
DATABASE_URL: postgres://myproject:myproject@db:5432/myproject
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/1
# SECRET_KEY is not here: it is an encrypted project variable, and Helm
# places it in every container.
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
services:
app:
<<: *app
# The Dockerfile's CMD starts gunicorn on 0.0.0.0:8000, the App Port.
worker:
<<: *app
command: celery -A myproject worker --loglevel=info --concurrency=2
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: myproject
POSTGRES_USER: myproject
POSTGRES_PASSWORD: myproject
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U myproject -d myproject"]
interval: 2s
timeout: 5s
retries: 30
redis:
image: redis:7-alpine
volumes:
db-data:
The database password can be a plain word here: nothing outside the preview's virtual machine can reach the database. Only the web service is reachable, through the preview's address.
The settings for this example
On your project's Settings → Preview Environments tab:
- Leave Compose File Path at
docker-compose.yml, Web Service atappand App Port at8000. -
Set Pre-deploy Command to create the tables and load seed data before the app starts:
docker compose run --rm --build app sh -c "python manage.py migrate --noinput && python manage.py loaddata seed.json" - Leave Start Command and First-deploy Command empty. The stack then starts with
docker compose up --build --detach --wait. - Click Save Changes.
- On the Container Environment Variables card, click Edit, then Add Variable. Name it
SECRET_KEY, give it a long random value, tick the lock checkbox next to the value so it is encrypted, and click Save Changes.
Each new preview then builds the image, runs the migrations and loads the seed data, starts
the app, the worker, PostgreSQL and Redis, and routes its address to app on port
8000.
Settings Helm refuses, and why
Before it starts the stack, Helm reads your Compose file with docker compose config
and refuses the preview if any service asks for one of these settings. Each would let a
container reach past its own walls: into the virtual machine, the host computer that runs the
virtual machine, or Helm's route to the preview. None is needed by a normal web app.
| Refused setting | Why |
|---|---|
privileged: true | It gives the container every power the virtual machine's administrator has, including access to its devices and kernel settings. |
cap_add | Linux capabilities are single administrator powers, such as changing network settings. Adding them gives the container powers Helm keeps from it. |
devices | It hands the virtual machine's hardware devices to the container. |
pid: host, network_mode: host, ipc: host | They let the container see and talk to the virtual machine's own processes, network and shared memory, including Helm's. |
A sysctls setting that is not limited to the container | It changes kernel settings for the whole virtual machine. Settings that affect only the container's own network, such as net.ipv4.ip_unprivileged_port_start, are allowed. |
A security_opt that turns off seccomp or AppArmor | Seccomp and AppArmor are the Linux filters that stop a container from making dangerous requests to the kernel. |
| A bind mount from outside your repository | A bind mount shares a folder of the virtual machine with a container. A folder inside the repository, such as ./config:/app/config, is allowed. A folder outside it, such as /var/run/docker.sock or /etc, would expose Helm's own files or control of Docker. Named volumes, such as db-data above, are always allowed. |
| Publishing the port Helm uses for the preview's route | Helm publishes your web service on one port of the virtual machine to route the preview's address to it. A ports: entry that takes that port would break the route. |
A refused preview fails at once, before anything starts. Helm also refuses a Compose file that
is not valid YAML, that has no service with the Web Service name, or whose
ports: clash with Helm's. The reason on the PR Previews page starts "Helm refused this preview's settings or Compose file. Fix the setting named below, then rebuild:"
and then names the service and the setting, for example "service app sets privileged". Remove
the setting, push the change, and click Rebuild.
ports: at all, because Helm publishes it. Keep
settings you use only on your own computer, such as ports: ["8000:8000"], in a
separate file such as docker-compose.override.yml. Docker Compose reads that file
on your computer when you run docker compose up, but Helm runs only the file named
in Compose File Path.
Resources
| What | Each preview gets |
|---|---|
| Processor | 2 cores, 64-bit x86 (linux/amd64) |
| Memory | 4 GiB, shared by every service in your Compose file |
| Disk | 40 GiB, shared by the images, the volumes and everything the services write |
- Helm applies these limits to every service, so one service cannot use more than the virtual machine has. Keep worker counts small, as in the example's
--workers 2and--concurrency=2. - Data is temporary. Everything the services write, including the database's volume, is deleted when the preview is rebuilt or torn down.
- The internet works; private networks do not. Services can call third-party APIs and download packages while they build, but cannot reach your company's own network, other previews or any private address. See "Network access" in Preview Lifecycle.
Check the file on your computer
You can run most of what Helm runs before you push. In the folder of your Compose file:
-
Check that Docker Compose can read the file. This prints the file with every value filled in, or the first error:
PREVIEW_DOMAIN=localhost PREVIEW_URL=http://localhost:8000 docker compose config -
Your portal variables exist only in a preview. On your computer, give the stack the values it needs yourself, for example with defaults in the Compose file (
NAME: ${NAME:-default}) or with an env file of your own that is not required, which Docker Compose 2.24 and later accept:env_file: - path: .env.local required: falseIn a preview, Helm's env file comes after this one, so the portal values win.
-
Start the stack the way Helm does, then look at each service:
PREVIEW_DOMAIN=localhost PREVIEW_URL=http://localhost:8000 docker compose up --build --detach --waitdocker compose psdocker compose logs app
On an Apple Silicon Mac, add DOCKER_DEFAULT_PLATFORM=linux/amd64 in front of the
commands to build and run the x86 images previews use. It is slower, but shows whether they work.
Read a failed preview's reason and logs
When a preview fails, Helm records why, and keeps the preview's logs.
- The reason is shown in red under the preview's row on the PR Previews page, and in
error_messagefromGET /api/previews/<id>/, so your GitHub Actions workflow can print it. Most reasons start with a short code and then the details, for examplepredeploy_failed: exit code 1orreadiness_failed: .... A reason that begins with "Helm refused this preview's settings or Compose file" means a preview setting or your Compose file broke one of the rules on this page, or the Compose file could not be read; the setting or the service is named after it. - When one of your commands fails, the reason ends with the last lines the command printed, which usually hold the error, such as a failed migration.
- The logs. Helm keeps the output of
docker compose up, the output of each command, anddocker compose logsfor every service. To see them, contact Helm support with the preview's address. To find most problems sooner, run the stack on your computer as described above and readdocker compose logs.
The PR Previews page and its statuses are described in The PR Previews Page.
Troubleshooting
The reason starts "Helm refused this preview's settings or Compose file"
A preview setting or your Compose file broke a rule. The rest of the reason names the setting or
the service. If a service asks for a setting Helm refuses, remove it using the table in
"Settings Helm refuses, and why". If the file is not valid YAML, run
docker compose config on your computer to find the line. Push the change and click
Rebuild.
The reason says the Compose file was not found
The branch Helm copied has no file at the Compose File Path. Check which branch was used (the Fallback Branch is used when the backend repository has no branch with the same name), and check the path's spelling and letter case.
The reason says the web service is not in the Compose file
The Web Service setting must match a name under services: exactly,
for example app. Change the setting or the file so they match.
The preview fails with readiness_failed
- The web service listens on another port, or only on
127.0.0.1. Make it listen on0.0.0.0at the App Port, or change App Port. - The web service answers
/with a 500 error, often because the database tables were not created. Run your migrations in the Pre-deploy Command. - The app redirects HTTP to HTTPS. Turn the redirect off in previews.
- Django answers
400 Bad Requestfor every request when the preview's domain is not inALLOWED_HOSTS. That still counts as an answer, but your testers see an error. SetALLOWED_HOSTS: ${PREVIEW_DOMAIN}as in the example.
My app cannot see my variables, or sees a different value
A value under the service's environment: wins over the portal value. Write it as
NAME: ${NAME:-default} to let the portal value through. A running preview keeps the
values it started with, so rebuild it after you change a variable.
The database or Redis container uses a value I did not expect
Every container receives your portal variables, including postgres and
redis. A portal variable named, for example, POSTGRES_PASSWORD,
POSTGRES_DB, REDIS_PASSWORD or PORT changes those images
too. Rename the variable, or set the image's value under its service's environment:,
which wins.
ALLOWED_HOSTS or CSRF_TRUSTED_ORIGINS is empty in the preview
The project renamed or turned off PREVIEW_DOMAIN or PREVIEW_URL on the
Container Environment Variables card. Use the name shown there in your Compose
file, or turn the variable back on.
The stack does not start in time, or a service is killed
All services share 4 GiB of memory and 2 processor cores. Lower the number of web workers and worker processes, and leave out services the preview does not need.