Skip to main content
This guide walks you through building and deploying an Astro application to Magic Containers with GitHub Container Registry. You’ll need:
  • A GitHub account for source code and container registry
Don’t have a bunny.net account yet? Sign up and enable Magic Containers to get started.

Create the Astro app

Create a new Astro project:

Add the Node adapter

Astro requires an adapter for server-side rendering. Install the Node adapter:
This updates your astro.config.mjs to include the adapter:
astro.config.mjs

Create an API route

Create a simple endpoint to test the deployment:
src/pages/index.json.ts

Run locally

Start the development server:
Visit http://localhost:4321 in your browser, or test the API route:

Create the Dockerfile

Dockerfile

Build and push to GitHub Container Registry

Create .github/workflows/build.yml to automatically build and push on every commit to main:
.github/workflows/build.yml
Push your code to trigger the workflow:
If your package is private, set the visibility to Public in GitHub or configure Magic Containers with registry credentials.

Deploy to Magic Containers

1

Create a new app

In the bunny.net dashboard, go to Magic Containers and click Add App. Enter a name and select your deployment option.
2

Add a container

Click Add Container, then configure:
3

Add an endpoint

Go to the Endpoints tab, click Add New Endpoint, and set the container port to 80.
4

Deploy

Click Add Container, then Next Step, and Confirm and Create.
For more details, see the quickstart guide.

Test your app

Visit your container URL in the browser to see your Astro site, or test the API route:
Response
You can add a custom hostname from the Endpoints section in your app settings.

Add Optimizer

Your CDN endpoint is already a pull zone in front of the app. Turn on Bunny Optimizer there, and a custom image service sends every <Image> width to the edge for resizing.
1

Configure the endpoint's pull zone

Open the pull zone that serves your CDN endpoint under CDN → Pull Zones. Turn on URL Query String vary, since endpoint pull zones ignore query strings by default and ?width=1080 would come back as the cached ?width=640 image.Enable Optimizer, then turn on the Dynamic Image API and automatic WebP under Optimizer → Settings. Astro already minifies CSS and JavaScript, so turn Optimizer’s minification off.
2

Add the image service

The service spreads Astro’s baseService, so Astro still works out the srcset widths, and only getURL changes. Without a baseURL, it returns relative URLs that go through the same pull zone.
src/bunny-image-service.ts
3

Point Astro at the service

astro.config.mjs
Rebuild and push the image. Smart Cache is on for endpoint pull zones, so the edge skips HTML and deploys need no purge.
To put a pull zone in front of Astro on another host, see Serve Astro from Bunny CDN.

Connect a database

You can connect your app to Bunny Database directly from the dashboard:
  1. Go to Database > [Your Database] > Access
  2. Click Generate Tokens
  3. Click Add Secrets to Magic Container App
  4. Select your app
The BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN environment variables are now available in your app:
src/pages/api/users.ts
See the TypeScript SDK documentation for more details.

Next steps

  1. Automate deploys with GitHub Actions
  2. Add a custom hostname
  3. Add a persistent volume
Last modified on October 15, 2026