Sign inSign up

jacoblincool/workerd

By jacoblincool

•Updated 8 months ago

Minimalist image for deploying cloudflare workers on self-hosted infrastructure.

Image
3

10K+

jacoblincool/workerd repository overview

⁠Workerd Docker Image

Supported Architectures: amd64, arm64

This minimalist Docker image allows you to run a Cloudflare Worker inside a Docker container, offering a simple solution for deploying and testing your worker on your infrastructure.

⁠Quick Start Guide

⁠Selflare

The fastest way to get your Cloudflare Worker running as a Docker container is to use Selflare⁠, which also supports KV, D1, R2, DO, and Cache API out of the box.

npm i -g selflare  # Install Selflare
selflare compile   # Compile yours worker to Cap'n Proto
selflare docker    # Generate Dockerfile and docker-compose.yml
docker compose up  # Run the worker

You can now access your worker at http://localhost:8080!

⁠Manual Setup

If you prefer to set up the Cap'n Proto manually, follow the steps below.

⁠1. Prepare Your Worker

First, build your worker with Wrangler by running the following command in your project directory:

wrangler deploy --dry-run --outdir .wrangler/dist

This command compiles your worker and outputs the result script to .wrangler/dist/index.js.

⁠2. Configure worker.capnp

Next, create a worker.capnp file in the same directory as your wrangler.toml. This file is used to configure the Workerd runtime. Below is a template you can start with:

using Workerd = import "/workerd/workerd.capnp";

const config :Workerd.Config = (
    services = [
        (name = "main", worker = .worker),
    ],
    sockets = [
        (service = "main", name = "http", address = "*:8080", http = ()),
    ]
);

const worker :Workerd.Worker = (
    modules = [
        (name = "worker", esModule = embed ".wrangler/dist/index.js"),
    ],
    compatibilityDate = "2024-02-19",
);

For detailed information on configuring worker.capnp, refer to the Workerd Repository⁠.

⁠3. Run the Docker Image

With your worker built and configured, you're ready to run it inside a Docker container. Execute the following command:

docker run -v $(pwd):/worker -p 8080:8080 jacoblincool/workerd

This command mounts your current directory to the /worker directory inside the container and forwards port 8080 to your local machine.

⁠Accessing Your Worker

After starting the Docker container, your worker will be accessible at http://localhost:8080.

⁠Use as a Base Image

You can also use this image as a base image for your own worker. Below is an example Dockerfile:

FROM jacoblincool/workerd

COPY worker.capnp worker.capnp
COPY other-file-like-your-worker.js other-file-like-your-worker.js

Tag summary

Content type

Image

Digest

sha256:ee95ab1a1…

Size

35.3 MB

Last updated

8 months ago

docker pull jacoblincool/workerd