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.
What It Creates
| File | Purpose |
|---|
Dockerfile | Multi-stage build for production |
.dockerignore | Excludes unnecessary files from build context |
Dockerfile Features
The generated Dockerfile uses a multi-stage build for optimal image size:
- Stage 1: Frontend Build - Builds the frontend assets using Node.js
- Stage 2: Backend Build - Compiles the Rust application with release optimizations
- 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
| Option | Description |
|---|
--with-mailpit | Include Mailpit email testing service |
--with-minio | Include MinIO S3-compatible storage service |
Default Services
PostgreSQL and Redis are always included:
| Service | Port | Description |
|---|
| PostgreSQL | 5432 | Primary database |
| Redis | 6379 | Caching and session storage |
Optional Services
When prompted (or using flags), you can add:
| Service | Ports | Description |
|---|
| Mailpit | 1025 (SMTP), 8025 (UI) | Local email testing |
| MinIO | 9000 (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:
Stop all services:
View logs:
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:
| Service | URL |
|---|
| PostgreSQL | localhost:5432 |
| Redis | localhost:6379 |
| Mailpit UI | http://localhost:8025 |
| MinIO Console | http://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:
-
Generate Docker files
kit docker:init
kit docker:compose
-
Create production environment file
cp .env .env.production
# Edit .env.production with production values
-
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
| Command | Creates | Purpose |
|---|
docker:init | Dockerfile, .dockerignore | Production deployment |
docker:compose | docker-compose.yml | Local development services |