Prerequisites
- A Cloudflare account on the Workers Paid plan, which Containers require.
- Docker running locally. Wrangler uses it to build the image.
- An Archil disk in the Archil region of your choice.
disk CLI. The output includes the disk ID and a one-time mount token, which grants access to this disk only:
Create the project
Create a directory for the project and install Wrangler:archil client. Cloudflare runs linux/amd64 images, and the installer picks the matching build:
Dockerfile
SIGTERM and unmounts the disk before it exits, which sends every buffered write to the disk and releases it:
start.sh
src/index.ts
wrangler.jsonc binds the Durable Object to the image and sets the disk ID and region:
wrangler.jsonc
vars with your disk ID and region.
Deploy and try it
Log in, deploy, and store the mount token as a Worker secret. The first deploy builds the image and pushes it to Cloudflare’s registry:SIGTERM, start.sh unmounts the disk, and the request returns once the container has exited:
How the disk behaves in a container
One container holds the disk at a time. A plain mount is exclusive. To mount the same disk in several containers at once, add--conditional to the archil mount command. Every container can then read and write anywhere on the disk; see Sharing disks. To give each user their own storage instead, create a disk per user and pass its ID and token to that user’s Durable Object.
Unmount when the container stops. Cloudflare sends a container SIGTERM when its inactivity timeout expires, and stop() sends it with signal(). Unmounting in the SIGTERM handler sends the client’s buffered writes to the disk and releases it for the next container. Stop containers with signal() rather than destroy(), which doesn’t give the container time to unmount. If a container ever goes away with the disk still mounted, see Release a stale lock.
Clean up
Delete the Worker, its container application and image, and the disk once you no longer need them.wrangler delete leaves the container application and its image behind, so delete those by ID and tag:
Next steps
- TypeScript SDK: read, write, and search the disk without mounting it.
- Sharing disks: mount one disk in many containers at once.
archilCLI reference: everyarchil mountoption.