NOTE: please see Cloudflare's official workerd
for running
Cloudflare Workers in local dev environment.
Cloudflare Workers are awesome! But what if you want to run workers in your dev environment, or in your own environment? Well, there is a great project (albeit, unmaintained) from Dollar Shave Club - cloudworker, which allows you to run Cloudflare Workers locally. Let's combine it with Nginx Unit, and run it in a Docker container.
Using an image built based on this repo as source in FROM
directive, one can
create a functional worker-in-a-box.
- Initialize submodule
git submodule init
git submodule update
- Build worker-in-a-box image
docker build -t worker .
- Use the image to package your Cloudflare Worker (see hello-world example)
# Dockerfile
FROM worker
docker build -t hello-world .
- Launch it
docker run -it --rm -p 8080:8080 hello-world
- Access it via http://localhost:8080
- patch cloudworker to support Redis as KV
- improve
lauch_worker.js
script to work with KV bindings - improve ONBUILD process