Skip to main content
Docker is a platform for packaging and running an application as a lightweight, portable container that encapsulates all the necessary dependencies.
This guide assumes you already have Docker Desktop installed.

Official images

Bun publishes official images to Docker Hub under oven/bun. Several variants are available:

Multi-stage Dockerfile

A multi-stage build separates dependency installation from the final release image, keeping the production image small and fast.
Dockerfile

.dockerignore

Create a .dockerignore file to exclude files from the build context. This speeds up builds and prevents secrets from leaking into the image.
.dockerignore

Build and run

1

Build the image

The -t flag names the image and --pull ensures Docker downloads the latest base image.
2

Run the container

Run in detached mode (-d) and map port 3000 on the container to port 3000 on your machine.
Visit http://localhost:3000 to confirm the app is running.
3

Stop the container

List running containers and stop by ID.

Docker Compose

For local development with multiple services, use Docker Compose:
docker-compose.yml
Start the stack with:

Health checks

Add a health check endpoint to your Bun server so Docker can monitor the container:
index.ts
The HEALTHCHECK instruction in the Dockerfile (or the healthcheck key in Compose) will poll this endpoint and mark the container as unhealthy if it fails.
Use oven/bun:debian instead of the default Alpine image when you need to install native packages (e.g., libvips for image processing) that require a glibc-based system.