Docker
This guide covers containerizing Azu applications with Docker for development, testing, and production deployments.
Dockerfile
Basic Dockerfile
# Dockerfile
FROM crystallang/crystal:1.15.1-alpine AS builder
# Install system dependencies
RUN apk add --no-cache \
build-base \
git \
libffi-dev \
openssl-dev \
sqlite-dev \
postgresql-dev \
mysql-dev
# Set working directory
WORKDIR /app
# Copy dependency files
COPY shard.yml shard.lock ./
# Install dependencies
RUN shards install --production
# Copy source code
COPY src/ ./src/
COPY lib/ ./lib/
# Build application
RUN crystal build --release src/azu-app.cr -o /app/bin/azu-app
# Production stage
FROM alpine:3.18
# Install runtime dependencies
RUN apk add --no-cache \
libc6-compat \
libffi \
openssl \
sqlite \
postgresql-client \
mysql-client
# Create app user
RUN addgroup -g 1000 -S azu && \
adduser -u 1000 -S azu -G azu
# Set working directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /app/bin/azu-app /app/bin/azu-app
# Copy static files
COPY public/ ./public/
# Change ownership
RUN chown -R azu:azu /app
# Switch to non-root user
USER azu
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
# Start application
CMD ["/app/bin/azu-app"]Multi-stage Dockerfile
Docker Compose
Development Environment
Production Environment
Docker Compose Overrides
Development Override
Testing Override
Nginx Configuration
Development Nginx
Production Nginx
Environment Configuration
Environment Files
Docker Secrets
Health Checks
Application Health Check
Docker Health Check
Monitoring and Logging
Log Configuration
Docker Logging
Scaling
Horizontal Scaling
Load Balancing
Security
Security Scanning
Non-root User
Development Workflow
Development Commands
Debugging
Next Steps
Learn about Production Deployment
Explore Scaling Strategies
Understand Monitoring and Alerting
Last updated
Was this helpful?
