Gate Docker Deployment
Gate Docker Setup
Section titled “Gate Docker Setup”This directory contains Docker configuration for the Gate (by Surkyl) API Gateway.
Quick Start
Section titled “Quick Start”Using Docker Compose (Recommended)
Section titled “Using Docker Compose (Recommended)”# From apps/gate directorydocker-compose up -d
# Or from repository rootdocker-compose -f apps/gate/docker-compose.yml up -dThe gateway will be available at http://localhost:8080
Using Docker CLI
Section titled “Using Docker CLI”# Build from repository rootdocker build -f apps/gate/Dockerfile -t gate:latest .
# Run the containerdocker run -d \ --name gate \ -p 8080:80 \ gate:latestBuild Options
Section titled “Build Options”Standard Build (No Version in Server Header)
Section titled “Standard Build (No Version in Server Header)”docker build -f apps/gate/Dockerfile -t gate:latest .Server Header: Server: Gate (by Surkyl)
Build with Version Header
Section titled “Build with Version Header”docker build \ --build-arg GATE_FEATURES="version-header" \ -f apps/gate/Dockerfile \ -t gate:versioned .Server Header: Server: Gate (by Surkyl)/0.1.0
Multi-Architecture Build
Section titled “Multi-Architecture Build”docker buildx build \ --platform linux/amd64,linux/arm64 \ -f apps/gate/Dockerfile \ -t gate:latest \ --push \ .Running
Section titled “Running”Basic Run
Section titled “Basic Run”docker run -d \ --name gate \ -p 8080:80 \ gate:latestWith Custom Environment Variables
Section titled “With Custom Environment Variables”docker run -d \ --name gate \ -p 8080:80 \ -e RUST_LOG=gate=debug,hypers=debug,tower_http=debug \ -e RUST_BACKTRACE=full \ gate:latestOn Port 80 (Requires Privileges)
Section titled “On Port 80 (Requires Privileges)”docker run -d \ --name gate \ -p 80:80 \ --cap-add=NET_BIND_SERVICE \ gate:latestHealth Check
Section titled “Health Check”The container includes a built-in health check that queries the /_health endpoint:
# Check container healthdocker ps
# View health check logsdocker inspect gate | jq '.[0].State.Health'Environment Variables
Section titled “Environment Variables”| Variable | Default | Description |
|---|---|---|
RUST_LOG | gate=info,hypers=info,tower_http=info | Logging configuration |
RUST_BACKTRACE | 1 | Enable backtraces (0=off, 1=on, full=verbose) |
Endpoints
Section titled “Endpoints”| Endpoint | Description |
|---|---|
/_health | Health check endpoint (global route) |
/* | All other routes return custom 404 page |
Docker Compose Configuration
Section titled “Docker Compose Configuration”Development Setup
Section titled “Development Setup”version: '3.8'
services: gate: build: context: ../.. dockerfile: apps/gate/Dockerfile args: GATE_FEATURES: '' ports: - '8080:80' environment: - RUST_LOG=gate=debug,hypers=debug,tower_http=debug - RUST_BACKTRACE=fullProduction Setup
Section titled “Production Setup”version: '3.8'
services: gate: image: gate:latest container_name: gate-prod ports: - '80:80' environment: - RUST_LOG=gate=warn,hypers=warn,tower_http=warn - RUST_BACKTRACE=0 restart: always cap_add: - NET_BIND_SERVICEImage Details
Section titled “Image Details”Build Stages
Section titled “Build Stages”- Planner - Generates cargo-chef recipe for dependency caching
- Builder - Builds dependencies and application binary
- Runtime - Minimal Debian-based runtime image
Image Sizes
Section titled “Image Sizes”| Image | Approximate Size |
|---|---|
| Builder Stage | ~2.5 GB |
| Final Runtime | ~80-120 MB |
| Compressed | ~40-60 MB |
Security Features
Section titled “Security Features”- ✅ Non-root user (
gate:gate) - ✅ Minimal runtime dependencies
- ✅ CA certificates included for HTTPS
- ✅ Health check endpoint
- ✅ No build tools in final image
Testing
Section titled “Testing”Test Health Endpoint
Section titled “Test Health Endpoint”# Using curlcurl http://localhost:8080/_health
# Using docker execdocker exec gate curl -f http://localhost:80/_healthView Logs
Section titled “View Logs”# Follow logsdocker logs -f gate
# Last 100 linesdocker logs --tail 100 gateCheck Server Header
Section titled “Check Server Header”curl -I http://localhost:8080/_health | grep ServerExpected output:
- Without version-header:
Server: Gate (by Surkyl) - With version-header:
Server: Gate (by Surkyl)/0.1.0
Troubleshooting
Section titled “Troubleshooting”Port 80 Permission Denied
Section titled “Port 80 Permission Denied”If you get permission errors binding to port 80:
- Use port mapping to a higher port:
-p 8080:80 - Grant NET_BIND_SERVICE capability:
--cap-add=NET_BIND_SERVICE - Run as root (not recommended):
--user root
Build Failures
Section titled “Build Failures”If cargo-chef build fails, try building without cache:
docker build --no-cache -f apps/gate/Dockerfile -t gate:latest .Container Won’t Start
Section titled “Container Won’t Start”Check logs for errors:
docker logs gateCommon issues:
- Port already in use (change
-pmapping) - Insufficient memory (increase Docker memory limit)
Cleanup
Section titled “Cleanup”# Stop and remove containerdocker-compose down
# Or with Docker CLIdocker stop gatedocker rm gate
# Remove imagedocker rmi gate:latest
# Clean up build cachedocker builder pruneCI/CD Integration
Section titled “CI/CD Integration”GitLab CI Example
Section titled “GitLab CI Example”build-gate: stage: build image: docker:24 services: - docker:24-dind script: - docker build -f apps/gate/Dockerfile -t $CI_REGISTRY_IMAGE/gate:$CI_COMMIT_SHA . - docker push $CI_REGISTRY_IMAGE/gate:$CI_COMMIT_SHAGitHub Actions Example
Section titled “GitHub Actions Example”- name: Build Docker Image run: | docker build -f apps/gate/Dockerfile -t gate:${{ github.sha }} . docker tag gate:${{ github.sha }} gate:latest