Deploy with Docker
Basic Dockerfile
# Build stage
FROM crystallang/crystal:1.17.1-alpine AS builder
WORKDIR /app
# Copy dependency files
COPY shard.yml shard.lock ./
# Install dependencies
RUN shards install --production
# Copy source code
COPY src/ src/
# Build release binary
RUN crystal build --release --static --no-debug src/app.cr -o bin/app
# Runtime stage
FROM alpine:3.19
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/bin/app .
# Copy static assets if any
COPY public/ public/
COPY views/ views/
# Create non-root user
RUN adduser -D -u 1000 appuser
USER appuser
EXPOSE 8080
ENV AZU_ENV=production
ENV PORT=8080
CMD ["./app"].dockerignore
Build and Run
Docker Compose
Development Compose
Production Compose with Nginx
Health Checks
Container Registry
CI/CD with Docker
See Also
Last updated
Was this helpful?
