Production Dockerfile
dockerfile
1# Multi-stage production build
2FROM ruby:3.2-slim AS builder
3
4RUN apt-get update && apt-get install -y \
5 build-essential \
6 libpq-dev \
7 git \
8 && rm -rf /var/lib/apt/lists/*
9
10WORKDIR /app
11
12COPY Gemfile Gemfile.lock ./
13RUN bundle config set deployment true && \
14 bundle config set without 'development test' && \
15 bundle install
16
17COPY . .
18RUN bundle exec rails assets:precompile
19
20# Production image
21FROM ruby:3.2-slim
22
23RUN apt-get update && apt-get install -y \
24 libpq5 \
25 && rm -rf /var/lib/apt/lists/*
26
27WORKDIR /app
28
29COPY /app /app
30COPY /usr/local/bundle /usr/local/bundle
31
32ENV RAILS_ENV=production \
33 RAILS_LOG_TO_STDOUT=true \
34 RAILS_SERVE_STATIC_FILES=true
35
36EXPOSE 3000
37
38CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]Production Compose
yaml
1services:
2 web:
3 image: ghcr.io/myorg/myapp:latest
4 restart: always
5 environment:
6 - RAILS_ENV=production
7 - SECRET_KEY_BASE=${SECRET_KEY_BASE}
8 - DATABASE_URL=${DATABASE_URL}
9 ports:
10 - "3000:3000"