docker.recipes

Deno HTTP Server

beginner

Secure JavaScript/TypeScript runtime with native HTTP server.

Overview

Deno is a modern JavaScript and TypeScript runtime built on Rust and the V8 JavaScript engine, created by Ryan Dahl (the original creator of Node.js) to address security and design issues in Node.js. Unlike Node.js, Deno is secure by default, requiring explicit permissions for file system access, network operations, and environment variables. It provides native TypeScript support without configuration, built-in tooling including formatters and linters, and uses URL-based module imports that eliminate the need for a package.json or node_modules directory. This Docker configuration creates a containerized Deno HTTP server that runs with minimal permissions, mounting your application code as read-only for enhanced security. The setup leverages Deno's built-in HTTP server capabilities through the Deno.serve() API, providing a lightweight web server that can handle modern JavaScript and TypeScript applications without additional dependencies or build steps. This stack is ideal for developers building modern web APIs, TypeScript enthusiasts wanting zero-configuration development environments, and security-conscious teams requiring explicit permission controls. The combination offers rapid prototyping capabilities with production-ready security features, making it perfect for serverless-style applications, REST APIs, and microservices that benefit from Deno's batteries-included approach and modern web standards compliance.

Key Features

  • Secure by default with explicit permission model requiring --allow-net and --allow-read flags
  • Native TypeScript support without transpilation configuration or build steps
  • Built-in HTTP server using Deno.serve() API with modern Request/Response objects
  • URL-based module imports eliminating package.json and node_modules complexity
  • Integrated development tools including formatter (deno fmt), linter (deno lint), and test runner
  • Web-standard APIs following modern browser specifications for consistent behavior
  • Single executable runtime with no external dependencies required
  • Read-only volume mounting for enhanced container security and immutable deployments

Common Use Cases

  • 1REST API backends for single-page applications requiring TypeScript without build complexity
  • 2Serverless function development and testing with security-first permission controls
  • 3Educational TypeScript projects where students can focus on code rather than tooling setup
  • 4Microservices architecture where each service needs minimal attack surface and explicit permissions
  • 5Rapid prototyping of web APIs with modern JavaScript features and zero configuration
  • 6Edge computing applications requiring lightweight runtime with built-in HTTP capabilities
  • 7Development teams migrating from Node.js seeking improved security and TypeScript experience

Prerequisites

  • Docker and Docker Compose installed on the host system
  • Basic understanding of JavaScript/TypeScript and HTTP server concepts
  • Minimum 128MB RAM allocated to Docker container (512MB recommended for production)
  • Port 8000 available on the host system for HTTP server binding
  • Application code directory structure with server.ts entry point file
  • Familiarity with Deno's permission system and command-line flags

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 deno:
3 image: denoland/deno:latest
4 container_name: deno-server
5 restart: unless-stopped
6 command: run --allow-net --allow-read /app/server.ts
7 volumes:
8 - ./app:/app:ro
9 ports:
10 - "8000:8000"
11 networks:
12 - deno-network
13
14networks:
15 deno-network:
16 driver: bridge

.env Template

.env
1# Deno server configuration

Usage Notes

  1. 1Docs: https://docs.deno.com/
  2. 2Secure by default - explicit permissions required (--allow-net, --allow-read)
  3. 3Native TypeScript support - no config needed
  4. 4Built-in formatter, linter, test runner, bundler
  5. 5Deno.serve() for HTTP: Deno.serve((req) => new Response('Hi'))
  6. 6Standard library at https://deno.land/std - batteries included

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 deno:
5 image: denoland/deno:latest
6 container_name: deno-server
7 restart: unless-stopped
8 command: run --allow-net --allow-read /app/server.ts
9 volumes:
10 - ./app:/app:ro
11 ports:
12 - "8000:8000"
13 networks:
14 - deno-network
15
16networks:
17 deno-network:
18 driver: bridge
19EOF
20
21# 2. Create the .env file
22cat > .env << 'EOF'
23# Deno server configuration
24EOF
25
26# 3. Start the services
27docker compose up -d
28
29# 4. View logs
30docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/deno-server/run | bash

Troubleshooting

  • PermissionDenied errors: Add required permission flags like --allow-net, --allow-read, or --allow-env to the command
  • Module not found from URL imports: Ensure internet connectivity in container and verify module URLs are accessible
  • Container exits immediately: Check that server.ts exists in ./app directory and contains proper Deno.serve() implementation
  • Port binding fails: Verify port 8000 is not in use by another service and matches the port in your Deno server code
  • TypeScript compilation errors: Deno's strict TypeScript checking may require proper type annotations unlike Node.js environments
  • Performance issues: Increase container memory allocation above 128MB minimum for production workloads

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

Components

deno

Tags

#deno#typescript#secure#runtime#rust

Category

Web Servers & Reverse Proxies
Ad Space