-
Notifications
You must be signed in to change notification settings - Fork 9.9k
[changelog] Support for Containers with the Cloudflare Vite plugin #23855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CarmenPopoviciu
merged 3 commits into
production
from
carmen/changelog-containers-in-vite-dev
Aug 1, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/content/changelog/workers/2025-07-22-containers-in-vite-dev.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: Develop locally with Containers and the Cloudflare Vite plugin | ||
| description: The Cloudflare Vite plugin now supports configuring Containers in your Worker | ||
| products: | ||
| - workers | ||
| date: 2025-07-22 | ||
| --- | ||
|
|
||
| import { WranglerConfig } from "~/components"; | ||
|
|
||
| You can now configure and run [Containers](/containers) alongside your [Worker](/workers) during local development when using the [Cloudflare Vite plugin](/workers/vite-plugin/). Previously, you could only develop locally when using [Wrangler](/workers/wrangler/) as your local development server. | ||
|
|
||
| #### Configuration | ||
|
|
||
| You can simply configure your Worker and your Container(s) in your Wrangler configuration file: | ||
|
|
||
| <WranglerConfig> | ||
| ```jsonc | ||
| { | ||
| "name": "container-starter", | ||
| "main": "src/index.js", | ||
| "containers": [ | ||
| { | ||
| "class_name": "MyContainer", | ||
| "image": "./Dockerfile", | ||
| "instances": 5, | ||
| "name": "hello-containers-go" | ||
| } | ||
| ], | ||
| "durable_objects": { | ||
| "bindings": [ | ||
| { | ||
| "class_name": "MyContainer", | ||
| "name": "MY_CONTAINER" | ||
| } | ||
| ] | ||
| }, | ||
| "migrations": [ | ||
| { | ||
| "new_sqlite_classes": [ | ||
| "MyContainer" | ||
| ], | ||
| "tag": "v1" | ||
| } | ||
| ], | ||
| } | ||
| ``` | ||
| </WranglerConfig> | ||
|
|
||
| #### Worker Code | ||
|
|
||
| Once your Worker and Containers are configured, you can access the Container instances from your Worker code: | ||
|
|
||
| ```ts | ||
| import { Container, getContainer } from "@cloudflare/containers"; | ||
|
|
||
| export class MyContainer extends Container { | ||
| defaultPort = 4000; // Port the container is listening on | ||
| sleepAfter = "10m"; // Stop the instance if requests not sent for 10 minutes | ||
| } | ||
|
|
||
| async fetch(request, env) { | ||
| const { "session-id": sessionId } = await request.json(); | ||
| // Get the container instance for the given session ID | ||
| const containerInstance = getContainer(env.MY_CONTAINER, sessionId) | ||
| // Pass the request to the container instance on its default port | ||
| return containerInstance.fetch(request); | ||
| } | ||
| ``` | ||
|
|
||
| #### Local development | ||
|
|
||
| To develop your Worker locally, start a local dev server by running | ||
|
|
||
| ```sh | ||
| vite dev | ||
| ``` | ||
|
|
||
| in your terminal. | ||
|
|
||
| #### Resources | ||
|
|
||
| Learn more about [Cloudflare Containers](https://developers.cloudflare.com/containers/) or the [Cloudflare Vite plugin](https://developers.cloudflare.com/workers/vite-plugin/) in our developer docs. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.