How to Deploy Ruby to Docker Without Writing a Dockerfile

M
Miget Team
Writer
January 6, 2026
5 min read

You can containerize any Ruby application without writing a Dockerfile using migetpacks. It auto-detects your Ruby version from .ruby-version or Gemfile, installs gems with bundler, automatically precompiles Rails assets, and produces an optimized production image. One command, zero configuration.


Why Is Writing a Dockerfile for Ruby So Complicated?

A production-ready Ruby Dockerfile requires:

  • Multi-stage builds to separate build dependencies from runtime
  • Installing native extension build tools (libpq-dev, libxml2-dev, etc.)
  • Proper bundler configuration for deployment
  • Rails asset precompilation with SECRET_KEY_BASE_DUMMY
  • Pruning gem cache after installation
  • Production environment variables (RAILS_ENV, RACK_ENV)
  • Non-root user for security

Most tutorials get the native gem dependencies wrong. You end up with images that fail to start because pg or nokogiri can't find their libraries.

How Do I Containerize a Ruby App Without a Dockerfile?

Open your terminal, navigate to your Ruby project, and run:

cd ~/projects/my-rails-app

docker run --rm \
  -v "$PWD":/workspace/source \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e OUTPUT_IMAGE=my-rails-app:latest \
  miget/migetpacks:latest

That's it. migetpacks will:

  1. Detect Ruby from your Gemfile
  2. Read version from .ruby-version or Gemfile
  3. Detect bundler version from Gemfile.lock
  4. Install system libraries for native gems
  5. Run bundle install with caching
  6. Precompile Rails assets automatically
  7. Output a slim production image

How Does migetpacks Detect My Ruby Version?

Version is resolved in this order:

PrioritySourceExample
1RUBY_VERSION env varRUBY_VERSION=3.3
2.ruby-version file3.4.4
3ruby declaration in Gemfileruby "3.3.0"
4DefaultLatest stable

The ruby- prefix is automatically stripped (e.g., ruby-3.2.0 becomes 3.2.0).

What Native Gems Does migetpacks Support?

migetpacks inspects your Gemfile and Gemfile.lock to install the correct system libraries:

GemBuild PackageRuntime Package
pglibpq-devlibpq5
mysql2, trilogylibmariadb-devlibmariadb3
sqlite3libsqlite3-devlibsqlite3-0
nokogiri, railslibxml2-dev, libxslt1-devlibxml2, libxslt1.1

No more "library not found" errors at runtime.

What Does the Generated Dockerfile Look Like?

# Builder stage
FROM ruby:3.4 AS builder
WORKDIR /build

COPY Gemfile Gemfile.lock ./
ENV GEM_HOME=/build/vendor/bundle
ENV BUNDLE_PATH=/build/vendor/bundle
RUN gem install bundler -v '2.5.0' --no-document && \
    bundle config set --local path '/build/vendor/bundle' && \
    bundle config set --local deployment 'true' && \
    bundle install --jobs 4 --retry 3

COPY . .

# Rails asset precompilation
ENV RAILS_ENV=production
ENV SECRET_KEY_BASE_DUMMY=1
RUN bundle exec rake assets:precompile && \
    bundle exec rake assets:clean && \
    rm -rf .git test spec vendor/bundle/ruby/*/cache

# Runtime stage
FROM ruby:3.4-slim
RUN apt-get update && apt-get install -y libpq5 tzdata ca-certificates
WORKDIR /app
COPY --from=builder /build /app

You never write or maintain this file - migetpacks handles it automatically.

How Does Rails Asset Precompilation Work?

If your project has a Rakefile and either app/assets/ or app/javascript/ directories, migetpacks automatically:

  1. Sets RAILS_ENV=production and SECRET_KEY_BASE_DUMMY=1
  2. Runs bundle exec rake assets:precompile
  3. Runs bundle exec rake assets:clean

No configuration needed.

What Runtime Environment Variables Are Set?

RAILS_ENV=production
RACK_ENV=production
RAILS_SERVE_STATIC_FILES=enabled
RAILS_LOG_TO_STDOUT=enabled
MALLOC_ARENA_MAX=2
DISABLE_SPRING=1
PUMA_PERSISTENT_TIMEOUT=95

Does migetpacks Support Node.js for Rails?

Yes. Ruby applications commonly use Node.js for asset compilation. When package.json is detected alongside a Ruby project, Node.js is automatically added:

cd ~/projects/my-rails-app

docker run --rm \
  -v "$PWD":/workspace/source \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e OUTPUT_IMAGE=my-rails-app:latest \
  -e BUILDPACKS=ruby,nodejs \
  miget/migetpacks:latest

How Do I Build Secure Distroless Images?

Enable Docker Hardened Images for minimal containers:

docker run --rm \
  -v "$PWD":/workspace/source \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e OUTPUT_IMAGE=my-app:latest \
  -e USE_DHI=true \
  miget/migetpacks:latest

DHI images are distroless - no shell, no package manager, minimal attack surface.

Next Steps

Stay UpdatedWith Latest Posts

Subscribe to our newsletter and never miss a new blog post, update, or special offer from the Miget team.