Cloudflare Workers (workerd)

workerd is the open-source runtime of Cloudflare Workers. It runs a Worker and its Durable Objects on your own server. It reads the wrangler.json or wrangler.jsonc file of your project.

This guide deploys one workerd instance with the Dockerfile build pack.

Requirements

  • A Git repository with a wrangler.jsonc (or wrangler.json) file, a Worker file, and a Dockerfile.
  • The Worker must be one ES module that is already bundled. The workerd image does not contain esbuild, so set "no_bundle": true. If your Worker has npm dependencies or TypeScript, see Bundle the Worker in the image.
  • workerd reads only the Wrangler keys that it supports. It stops at startup when it finds a key that it does not support, for example routes, env, or services. Refer to Cloudflare compatibility.

Example project

This example is a Worker with one Durable Object that counts requests.

wrangler.jsonc:

{
  "name": "hello-workerd",
  "main": "index.js",
  "compatibility_date": "2026-11-01",
  "no_bundle": true,
  "durable_objects": {
    "bindings": [{ "name": "COUNTER", "class_name": "Counter" }]
  },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }]
}

index.js:

import { DurableObject } from "cloudflare:workers";

export class Counter extends DurableObject {
  async fetch() {
    const count = ((await this.ctx.storage.get("count")) ?? 0) + 1;
    await this.ctx.storage.put("count", count);
    return new Response(`Count: ${count}\n`);
  }
}

export default {
  async fetch(request, env) {
    const stub = env.COUNTER.get(env.COUNTER.idFromName("global"));
    return stub.fetch(request);
  },
};

Dockerfile:

FROM docker.io/cloudflare/workerd:latest
COPY . /app/
CMD ["--data-dir=/data"]

The image runs workerd serve /app --socket-addr=http=*:8787. It adds the CMD arguments to this command. The --data-dir=/data argument keeps the data of Durable Objects, D1, KV, Queues, and Workflows in /data.

Always set --data-dir

The container runs as a non-root user and cannot write to /app. Without --data-dir, workerd keeps state in /app/.wrangler/state/workerd, and experimental features stop at startup with Permission denied.

Pin a version tag in place of latest (for example cloudflare/workerd:2026-12-03) to get the same runtime on each deployment.

Deploy on Coolify

Create the application

Open your project and environment, then select + New. Select your Git repository, and choose Dockerfile in Build pack. Refer to Dockerfile for the full steps.

Set the port

Set Ports Exposes to 8787. Add a domain for the application.

workerd listens on 0.0.0.0:8787 in the image, so the Coolify proxy can connect to it. It serves plain HTTP. The Coolify proxy adds HTTPS.

Add persistent storage

Open Persistent Storage, and add a Volume mount with the destination path /data. Refer to Persistent storage.

Without this volume, all Durable Object data is lost when the container restarts or you deploy again.

Keep the health check disabled

The workerd image does not contain a shell, curl, or wget. A Coolify HTTP or CMD health check cannot run in the container, and Docker marks the container as unhealthy. Keep the health check disabled. Refer to Health checks.

Deploy and verify

Select Deploy. The logs show Listening on http://localhost:8787.

Open your domain two times. The response changes from Count: 1 to Count: 2. Restart the application and open the domain again. The count continues from the last value, because the data is in the /data volume.

Environment variables and secrets

workerd does not give container environment variables to the Worker. An environment variable that you add in Coolify is not in env.

  • Values that are not secret: put them in vars in wrangler.jsonc.
  • Secrets: use a Secrets Store binding. workerd reads the value from the WORKERD_SECRET_<NAME> environment variable at startup. The name is in uppercase, and each character that is not a letter or a digit becomes _.

Example for a secret with the name api-key:

{
  "secrets_store_secrets": [
    { "binding": "API_KEY", "store_id": "local", "secret_name": "api-key" }
  ]
}

In Coolify, add the environment variable WORKERD_SECRET_API_KEY. In the Worker, read it with await env.API_KEY.get().

The Secrets Store binding is experimental. Add --experimental to the CMD:

CMD ["--experimental", "--data-dir=/data"]

Experimental services

D1, R2, KV, Queues, Workflows, Cron Triggers, Static Assets, the Cache API, and Secrets Store are experimental in workerd. To use them, add --experimental to the CMD. Workers and Durable Objects do not need this flag.

Bundle the Worker in the image

When your Worker uses npm packages or TypeScript, bundle it in a build stage. Then copy the bundled file into the workerd image.

FROM node:22-alpine AS build
WORKDIR /src
COPY package*.json ./
RUN npm ci
COPY . .
RUN npx esbuild src/index.ts --bundle --format=esm --platform=browser \
    --conditions=workerd,worker --external:cloudflare:* --external:node:* \
    --outfile=dist/index.js

FROM docker.io/cloudflare/workerd:latest
COPY --from=build /src/dist/index.js /app/index.js
COPY wrangler.jsonc /app/wrangler.jsonc
CMD ["--data-dir=/data"]

Set "main": "index.js" and "no_bundle": true in wrangler.jsonc. Add esbuild to the devDependencies of package.json.

Clustering

workerd can run as a cluster of instances that share one S3-compatible bucket (Cloudflare R2, Amazon S3, or Google Cloud Storage). This feature is experimental.

Coolify deploys one container for each application. A cluster needs more than one instance, and each instance must connect to the cluster port of the other instances on a private network. The cluster port is not encrypted. Never make it public. Refer to the workerd cluster guide before you use it.

Security

workerd is not a hardened sandbox. Run only code that you trust in it. Refer to workerd security.

On this page