Skip to content

Docker Development Environment for Old Ruby Versions

Juan Vásquez edited this page Apr 28, 2026 · 1 revision

Testing against specific Ruby versions locally is essential for catching version-specific bugs. This guide explains how to use Docker to test next_rails against Ruby 2.3+ without installing multiple Ruby versions on your system.

Why Docker?

Legacy Ruby versions (2.3, 2.4, 2.5) can be difficult to install and maintain locally. Version-specific syntax issues (like Ruby 2.3 block parameter parsing) only appear when testing on those versions. Docker solves this by providing isolated Ruby environments.

Setup

  1. Ensure you have Docker and docker compose installed
  2. Create docker compose.yml in the project root with the content below
  3. Run docker compose run ruby-2.3 to get started

docker compose.yml

services:
  ruby-2.3:
    image: ruby:2.3
    container_name: next_rails_ruby_2_3
    working_dir: /app
    volumes:
      - .:/app
    command: bash -c "gem install bundler:1.17.3 && bundle _1.17.3_ install && bash"
    stdin_open: true
    tty: true

Quick Start

# Interactive shell on Ruby 2.3
docker compose run ruby-2.3

# Inside the container
bundle _1.17.3_ exec rspec ./spec/deprecation_tracker_spec.rb

Common Tasks

Run full test suite on Ruby 2.3

docker compose run ruby-2.3 bash -c "bundle _1.17.3_ install --quiet && bundle _1.17.3_ exec rake"

Run specific file on Ruby 2.3

docker compose run ruby-2.3 bash -c "bundle _1.17.3_ install --quiet && bundle _1.17.3_ exec rspec ./spec/deprecation_tracker_spec.rb"

Interactive shell on Ruby 2.3

docker compose run ruby-2.3
# Now you're in a container with Ruby 2.3
# You can run bundle, rspec, irb, etc.

Cleanup

docker compose down

This removes the containers but keeps images for faster subsequent runs.

Requirements

  • Docker
  • docker compose

See Docker documentation to install.