This guide assumes you already have Docker Desktop installed.
Official images
Bun publishes official images to Docker Hub underoven/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 (Visit http://localhost:3000 to confirm the app is running.
-d) and map port 3000 on the container to port 3000 on your machine.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
Health checks
Add a health check endpoint to your Bun server so Docker can monitor the container:index.ts
HEALTHCHECK instruction in the Dockerfile (or the healthcheck key in Compose) will poll this endpoint and mark the container as unhealthy if it fails.