Dockerize Ruby on Rails: Fast Deploys, Reproducible Builds
Rails apps carry heavy dependencies — native gems like nokogiri, asset compilation, and database drivers all need specific system libraries. We build multi-stage Dockerfiles that compile native extensions in a build stage, precompile assets, and produce slim runtime images with only what Rails needs to serve requests.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Why Dockerize Ruby on Rails
Rails deployments are brittle without containerization. Bundler version mismatches, missing libxml2 headers for Nokogiri, and different ImageMagick versions between environments cause silent failures that are painful to debug.
Docker freezes the entire runtime stack — Ruby version, system libraries, gems, and configuration — into a single artifact. Every deployment is identical to what you tested, and rollbacks are instant because you just swap image tags.
Our Docker Implementation for Ruby on Rails
Multi-stage Dockerfile separating build and runtime:
- Build stage:
FROM ruby:3.3-slim AS builder— installsbuild-essential,libpq-dev, and other native extension dependencies. Runsbundle config set --local deployment truethenbundle install. For apps with a JS frontend, runsrails assets:precompilewith Node.js installed in this stage only. - Runtime stage:
FROM ruby:3.3-slim— installs only runtime libraries (libpq5,libvipsfor Active Storage). Copiesvendor/bundleand precompiled assets from the builder. SetsRAILS_ENV=production,RAILS_SERVE_STATIC_FILES=1, and runs as a non-root user.
Compose config includes Puma with appropriate worker/thread counts, a health check hitting /up (Rails 7.1+ built-in health check), and depends_on with the database service condition.
What You Get
- Multi-stage
Dockerfilewith precompiled assets — 250-400 MB final image docker-compose.ymlwith Postgres, Redis, and Sidekiq services- Entrypoint script that runs
rails db:prepareon first boot - Health check on Rails 7.1+
/upendpoint .dockerignoreexcludingtmp/,log/,.git,node_modules- CI pipeline with bundle cache layer optimization
Why Anubiz Engineering
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.