Deploy with Docker

This guide shows you how to containerize and deploy your Azu application with Docker.

Basic Dockerfile

Create a multi-stage 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

Create a .dockerignore file:

Build and Run

Docker Compose

Create docker-compose.yml:

Development Compose

Create docker-compose.dev.yml:

Development Dockerfile:

Production Compose with Nginx

Nginx configuration:

Health Checks

Add health check to Dockerfile:

Container Registry

Push to a registry:

CI/CD with Docker

GitHub Actions example:

See Also

Last updated

Was this helpful?