Running a Bun application on Serverless Containers
Bun is an all-in-one JavaScript and TypeScript runtime toolkit built for speed, combining a fast bundler, transpiler, and package manager in a single binary. Hosting Bun on Scaleway Serverless Containers provides automatic scaling, simplified deployment, and reduced infrastructure management. Thanks to Bun's quick startup time and small memory footprint, this combination is a great fit for serverless workloads, allowing you to minimize cold starts while focusing on writing code rather than maintaining servers.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- Installed Docker or Docker Engine
- Installed Bun on your local machine
- Created a Scaleway Container Registry namespace and logged into it
Create and host a basic Bun application
To host a Bun web application on Scaleway Serverless Containers, you need to create a Bun project, implement a simple HTTP server using the native Bun.serve API, and containerize it using a production-ready Dockerfile. After building the image locally, push it to the Scaleway Container Registry and deploy it via Scaleway Serverless Containers.
Create your app and test it locally
-
In a terminal, create a new directory and navigate into it:
mkdir my-bun-app cd my-bun-app -
Initialize a new Bun project:
bun init -y -
Create a
srcdirectory and add anindex.tsfile with the following code. This starts a simple HTTP server using Bun's nativeBun.serveAPI:const PORT = process.env.PORT || 3000; const server = Bun.serve({ port: PORT, fetch(req) { const url = new URL(req.url); if (url.pathname === "/") { return new Response("Hello from Bun on Scaleway Serverless Containers!"); } return new Response("Not Found", { status: 404 }); }, }); console.log(`Bun app running on http://localhost:${server.port}`); -
Verify your project structure:
my-bun-app/ ├── src/ │ └── index.ts # HTTP server entry point ├── package.json # Dependencies and scripts ├── bun.lockb # Locked dependencies └── tsconfig.json # TypeScript configuration -
Run the following command to start your application locally:
bun run src/index.tsVisit http://localhost:3000 to view your running Bun application.
Build the app image and push it to Scaleway Container Registry
Before building and pushing your image, ensure you have created a Scaleway Container Registry namespace, and logged into it with the Docker CLI.
-
Create a
Dockerfileat the root of your Bun app:# Use the official Bun image FROM oven/bun:1 # Set working directory WORKDIR /app # Copy the application code COPY . . # Expose port EXPOSE 3000 # Run the Bun application CMD ["bun", "run", "src/index.ts"] -
Create a
.dockerignorefile in the same directory as your Dockerfile to keep the image lightweight:node_modules .git -
Build, tag, and push the image to Scaleway Container Registry:
docker build \ --platform linux/amd64 \ --push \ -t <CONTAINER_REGISTRY_ENDPOINT>/my-bun-app:latest .
Deploy your app using Serverless Containers
-
Deploy a Serverless Container with the following settings:
- Registry: Scaleway Container Registry
- Registry namespace: The namespace where you pushed your image
- Container port:
3000as it is the port exposed in the dockerfile - Resources:
500 mVCPUand512 MBmemory - Autoscaling: Set minimum scale to
1to avoid cold starts (optional)
Deployment may take up to a minute.
-
Once the container is ready, click the container endpoint in the Overview tab. Your Bun app is live and accessible to anyone with the link.
Going further
- You can deploy an existing Bun project by building and pushing its container image as shown above.
- Add a custom domain to your deployed app.
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center