Bun HTTP Server
Ultra-fast JavaScript runtime with built-in HTTP server.
Overview
Bun is a revolutionary JavaScript runtime built from the ground up in Zig, designed to be a drop-in replacement for Node.js with dramatically improved performance. Created by Jarred Sumner at Oven, Bun combines a JavaScript runtime, bundler, test runner, and package manager into a single binary, eliminating the need for separate tools like webpack, jest, or npm. What sets Bun apart is its incredible speed - up to 4x faster than Node.js for many operations - and its native support for TypeScript and JSX without requiring compilation steps.
This Docker configuration leverages Bun's built-in HTTP server capabilities through the Bun.serve() API, which provides one of the fastest web server implementations available in the JavaScript ecosystem. The container runs a TypeScript server file directly, taking advantage of Bun's native TypeScript execution without transpilation overhead. The setup mounts your application code as a volume, enabling hot-reload development while maintaining the performance benefits of Bun's optimized runtime.
This stack is ideal for developers seeking maximum performance from their JavaScript applications, teams migrating from Node.js who want faster build times and execution, and projects requiring a lightweight yet powerful web server solution. Startups benefit from Bun's all-in-one approach that reduces toolchain complexity, while performance-critical applications gain from its superior request handling and lower memory footprint compared to traditional Node.js setups.
Key Features
- Native TypeScript and JSX execution without compilation or transpilation steps
- Built-in HTTP server with Bun.serve() API delivering 4x faster performance than Node.js
- Integrated package manager compatible with npm packages and lockfiles
- Hot-reload development support with volume mounting for live code changes
- All-in-one runtime combining bundler, test runner, and package manager in single binary
- Zig-powered engine providing significantly lower memory usage and faster startup times
- Drop-in Node.js compatibility allowing existing npm ecosystem usage
- Built-in WebSocket support with optimized performance for real-time applications
Common Use Cases
- 1High-performance API servers requiring maximum request throughput and low latency
- 2TypeScript-first web applications wanting to skip build pipeline complexity
- 3Development environments needing fast hot-reload and instant TypeScript execution
- 4Microservices architectures where startup time and memory efficiency are critical
- 5Real-time applications using WebSockets for chat, gaming, or live data streaming
- 6Migration projects moving from Node.js to gain performance improvements without code changes
- 7Prototyping and MVP development where quick iteration and minimal setup are priorities
Prerequisites
- Docker and Docker Compose installed with support for Linux containers
- Application directory structure with server.ts file in ./app/ folder
- Basic understanding of JavaScript/TypeScript and HTTP server concepts
- Port 3000 available on host system for web server access
- Minimum 512MB RAM allocated to Docker for optimal Bun performance
- Understanding of Bun.serve() API and fetch handler function structure
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 bun: 3 image: oven/bun:latest4 container_name: bun-server5 restart: unless-stopped6 working_dir: /app7 command: bun run server.ts8 volumes: 9 - ./app:/app10 ports: 11 - "3000:3000"12 networks: 13 - bun-network1415networks: 16 bun-network: 17 driver: bridge.env Template
.env
1# Bun server configurationUsage Notes
- 1Docs: https://bun.sh/docs
- 2Fastest JavaScript runtime (written in Zig)
- 3Built-in bundler, test runner, package manager
- 4Drop-in Node.js replacement - npm packages work
- 5Native TypeScript/JSX support - no transpilation needed
- 6HTTP server: Bun.serve({ fetch(req) { return new Response('Hi') } })
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 bun:5 image: oven/bun:latest6 container_name: bun-server7 restart: unless-stopped8 working_dir: /app9 command: bun run server.ts10 volumes:11 - ./app:/app12 ports:13 - "3000:3000"14 networks:15 - bun-network1617networks:18 bun-network:19 driver: bridge20EOF2122# 2. Create the .env file23cat > .env << 'EOF'24# Bun server configuration25EOF2627# 3. Start the services28docker compose up -d2930# 4. View logs31docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/bun-server/run | bashTroubleshooting
- Container exits immediately: Ensure server.ts exists in ./app/ directory and contains valid Bun.serve() configuration
- Port 3000 connection refused: Verify server.ts binds to '0.0.0.0' instead of 'localhost' for Docker networking
- TypeScript errors on startup: Check Bun version compatibility with your TypeScript syntax and decorators usage
- Hot reload not working: Confirm ./app volume mount path matches your local project structure and file permissions
- Package installation failures: Verify package.json exists and run 'bun install' command before 'bun run server.ts'
- High memory usage: Monitor for memory leaks in fetch handlers and ensure proper response object cleanup
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download