Skip to main content
Kit provides commands to generate Docker configuration files for both local development and production deployment.

docker:init

Generate a production-ready, multi-stage Dockerfile optimized for Rust applications.
kit docker:init

What It Creates

FilePurpose
DockerfileMulti-stage build for production
.dockerignoreExcludes unnecessary files from build context

Dockerfile Features

The generated Dockerfile uses a multi-stage build for optimal image size:
  1. Stage 1: Frontend Build - Builds the frontend assets using Node.js
  2. Stage 2: Backend Build - Compiles the Rust application with release optimizations
  3. Stage 3: Runtime - Minimal Debian-based image with only runtime dependencies
# Stage 1: Build Frontend
FROM node:20-alpine AS frontend-builder
# ... builds frontend assets

# Stage 2: Build Rust Backend
FROM rust:1.75-slim-bookworm AS backend-builder
# ... compiles Rust with cargo build --release

# Stage 3: Runtime Image
FROM debian:bookworm-slim AS runtime
# ... minimal runtime with ca-certificates and libssl

Building and Running

After generating the Dockerfile:
# Build the image
docker build -t my-app .

# Run the container
docker run -p 8080:8080 --env-file .env.production my-app
Create a .env.production file with your production environment variables. Never commit this file to version control.

docker:compose

Generate a docker-compose.yml file for local development with common services.
kit docker:compose [OPTIONS]

Options

OptionDescription
--with-mailpitInclude Mailpit email testing service
--with-minioInclude MinIO S3-compatible storage service

Default Services

PostgreSQL and Redis are always included:
ServicePortDescription
PostgreSQL5432Primary database
Redis6379Caching and session storage

Optional Services

When prompted (or using flags), you can add:
ServicePortsDescription
Mailpit1025 (SMTP), 8025 (UI)Local email testing
MinIO9000 (API), 9001 (Console)S3-compatible object storage

Examples

# Interactive mode - prompts for optional services
kit docker:compose

# Include all optional services
kit docker:compose --with-mailpit --with-minio

# Include only email testing
kit docker:compose --with-mailpit

Generated Configuration

The generated docker-compose.yml includes:
  • Environment variable defaults - Uses ${VAR:-default} syntax for easy customization
  • Health checks - All services include health checks for reliability
  • Persistent volumes - Data is preserved between container restarts
  • Custom network - Services communicate on an isolated network

Using the Services

Start all services:
docker compose up -d
Stop all services:
docker compose down
View logs:
docker compose logs -f

Environment Configuration

Update your .env file to use the Docker services:
# PostgreSQL
DATABASE_URL=postgres://kit:kit_secret@localhost:5432/kit_db

# Redis (if using caching)
REDIS_URL=redis://localhost:6379

# Mailpit (if enabled)
MAIL_HOST=localhost
MAIL_PORT=1025

# MinIO (if enabled)
S3_ENDPOINT=http://localhost:9000
S3_ACCESS_KEY=minioadmin
S3_SECRET_KEY=minioadmin

Customizing Ports

Override default ports using environment variables:
# In your shell or .env file
DB_PORT=5433 docker compose up -d

# Or set them in .env
DB_PORT=5433
REDIS_PORT=6380
MAILPIT_SMTP_PORT=2025
MAILPIT_UI_PORT=8026
MINIO_API_PORT=9002
MINIO_CONSOLE_PORT=9003

Service URLs

After starting, access services at:
ServiceURL
PostgreSQLlocalhost:5432
Redislocalhost:6379
Mailpit UIhttp://localhost:8025
MinIO Consolehttp://localhost:9001
Mailpit captures all outgoing emails from your application. Access the web UI to view sent emails during development.

Production Deployment

For production deployment, combine both commands:
  1. Generate Docker files
    kit docker:init
    kit docker:compose
    
  2. Create production environment file
    cp .env .env.production
    # Edit .env.production with production values
    
  3. Build and run
    docker build -t my-app .
    docker run -d -p 8080:8080 --env-file .env.production my-app
    

Docker Compose for Production

For production with Docker Compose, you might want to add your application service. Create a docker-compose.prod.yml:
services:
  app:
    build: .
    ports:
      - "8080:8080"
    env_file:
      - .env.production
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
Run with:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Summary

CommandCreatesPurpose
docker:initDockerfile, .dockerignoreProduction deployment
docker:composedocker-compose.ymlLocal development services