Docs/Candor Deploy
Multi-service apps and docker compose
Run a web app, a worker and a database together as one project, from a docker compose file or added by hand; manage each service; and fix database errors during a Next.js build.
Many apps are more than one process: a web server, a background worker, a database, a cache. In Candor Deploy these run as services of one project. Each service is its own container with its own environment variables, logs and volumes. They share a private network, so they reach each other by service name.
You get services from a docker compose file in your repository, by adding them in the dashboard, or both.
From a docker compose file
If your repository has a compose file at its root (docker-compose.yml, docker-compose.yaml, compose.yml or compose.yaml), each service in it becomes a service of the project. If the file is somewhere else or has another name, enter its path (or its folder) in Compose file on the Config screen and press Scan.
These compose fields are used: image, build, dockerfile, ports, depends_on, environment, volumes, command, restart and healthcheck. Everything else in the file, such as networks, labels and profiles, is left alone.
Some things are refused for safety: mounting a path from the server, mounting the Docker socket, privileged, added capabilities and the host’s network. Use named volumes such as pgdata:/var/lib/postgresql/data. See Builds and configuration.
Candor Deploy never writes to your repository. Changes you make in the dashboard are stored with the project and used on every deploy. To change the file itself, edit it and push.
What build: means
build: is the folder Docker builds from. COPY paths in that service’s Dockerfile are relative to it, dockerfile: is looked for inside it, and its .dockerignore applies. Relative paths are resolved from the compose file’s own folder, as docker compose does. A service whose build folder has no Dockerfile fails with an error; another Dockerfile in the repository is not used instead.
build.args and build.target are not read. Build arguments come from the service’s environment variables, each passed as a --build-arg.
Modern Dockerfile features such as RUN --mount=type=cache need BuildKit, which is used when the Dockerfile asks for it. The build log says which builder ran.
Database access during a Next.js build
If next build fails with getaddrinfo ENOTFOUND db, often followed by something like Failed to collect page data for /api/hours, code that ran during the build tried to connect to your database by its service name.
That cannot work. The build does not wait for your database to start, and it is not on the services’ private network, so even a database that is already running cannot be reached as db from the build. depends_on (or "dependsOn" in openship.json) only orders how containers start; it does not help the build.
The fix is to connect when a request arrives, not when the module loads. Next.js imports route modules during the build, so a connection made at the top of a file, or in a helper it imports, runs then. export const dynamic = 'force-dynamic' alone does not stop that.
For example, with Payload in a Next.js route handler, move the initialisation inside the handler:
import config from "@payload-config";
import { getPayload } from "payload";
export const dynamic = "force-dynamic";
export async function GET() {
const payload = await getPayload({ config });
const result = await payload.find({
collection: "hours",
overrideAccess: false,
});
return Response.json(result);
}
Keep your existing authentication and access checks when you adapt this. Check the imported helpers and config files for the same kind of top-level connection.
At runtime, keep the connection string pointing at the service name, such as db:5432; that works once both services are running.
If a page really needs data while it is generated at build time, moving an API handler will not help. Either give the build a data source it can reach, or load that page’s data at request time.
Adding a service by hand
Any project can have extra services, from a catalog of common images (databases, caches, search, queues, object storage and more) or from any Docker image.
- Open the project, then Apps & Services, and add a service. The Add an app or service dialog opens.
- Pick from the catalog, search by name, or choose Custom image and enter an image and tag.
- Check the details:
- Name: short and unique in the project, such as
db. Other services use it as the host name. - Ports: the port or ports the container listens on, such as
5432. - Image: the image and tag, such as
postgres:16-alpine. - Persistent volumes: name and container path pairs, so data survives restarts and redeploys.
- Environment variables the service needs.
- Whether it is internal only (the right choice for databases and workers) or has a public address on a domain you own.
- Name: short and unique in the project, such as
- Press Add.
If the project is already deployed, adding a service redeploys it so the new container starts. If not, the service is saved and starts on the first deploy.
Working with a service
Open the project, then Apps & Services, and select a service. Each row shows whether the service is public or internal and its status. A service has these tabs:
- Overview: its internal address, ports, configuration and volumes.
- Logs: its output, live.
- Environment: its own variables. Press Save environment, then apply or redeploy for the change to take effect.
- Terminal: a shell inside the running container.
- Settings: name, image or build, ports, depends-on, volumes, command, restart policy and health check, and the buttons below.
The buttons on Settings depend on the state:
- Running: Stop and Restart.
- Stopped: Start.
- Never started: Enable & start.
- Redeploy rebuilds only this service and leaves the others running.
- Disable Service skips it on deploys. Delete removes it.
Restarting or redeploying a service restarts its container, so expect a short interruption to that service.
When the compose file and your edits disagree
On every deploy the current compose file is read again and merged with your service settings, field by field:
| The file changed? | You edited that field? | Result |
|---|---|---|
| No | Either | Your value is kept. |
| Yes | No | The file’s new value is used. |
| Yes | Yes | Your edit is kept; the file’s other changes are applied. |
| A new service appears | It is added. | |
| A service is removed | No | It is removed if it has no saved environment. |
| A service is removed | Yes | It is kept until you delete it. |
When the compose file has changed, the deploy waits for you to review the changed services on the Config screen, then deploy again. Saved environment variables are kept, even if a key disappears from the file. Remove a variable yourself in the environment editor when you no longer need it.
Troubleshooting
I added a service but nothing is running. A container only starts on a deploy. Deploy the project, or press Enable & start on the service’s Settings tab.
A service cannot reach another. Use the other service’s name as the host and its container port, for example redis:6379, not localhost.
Data was lost after a deploy. The container’s own filesystem is replaced on every deploy. Put data in a named volume. See persistent storage. A volume lives on the same server; it is not a copy kept anywhere else.
More in Troubleshooting deploys.
Related
Something here wrong, unclear or missing? Tell us. Docs get fixed like bugs.
Not a customer yet? Start a free trial, or see plans and limits.