Skip to main content
Yoosuf Mohamed

Engineering

Setting Up a Legacy Rails 4.2.6 Project with Docker in 2024

How to set up and run a legacy Rails 4.2.6 project in 2024 using Docker to isolate outdated dependencies.

1 min read

By Yoosuf Mohamed, Systems Architect

Working on a legacy Rails 4.2.6 project in 2024 can be challenging due to outdated dependencies and potential compatibility issues. Setting up the environment with Docker is a good approach, as it can help isolate dependencies and ensure consistency across development environments. Here’s how you can proceed:

Setting Up the Environment with Docker

  1. Install Docker: Ensure Docker is installed on your system. This includes Docker Engine and Docker Compose.

  2. Create a Dockerfile : Create a Dockerfile to define the environment. Here’s an example Dockerfile for Rails 4.2.6:

             FROM ruby:2.3.8
    
    # Install dependencies
    RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
    
    # Set up the working directory
    WORKDIR /app
    
    # Copy the Gemfile and Gemfile.lock into the container
    COPY Gemfile* /app/
    
    # Install gems
    RUN gem install bundler -v '<2.0' && bundle install
    
    # Copy the rest of the application code
    COPY . /app
    
    # Expose port 3000 to access the Rails server
    EXPOSE 3000
    
    # Start the Rails server
    CMD ["rails", "server", "-b", "0.0.0.0"]              
  3. Create a docker-compose.yml File: Set up docker-compose.yml to define services. For example:

             version: '3'
    services:
      db:
        image: postgres:9.6
        environment:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
        volumes:
          - db_data:/var/lib/postgresql/data
    
      web:
        build: .
        command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -b 0.0.0.0"
        volumes:
          - .:/app
        ports:
          - "3000:3000"
        depends_on:
          - db
    
    volumes:
      db_data:              
  4. Adjust Gemfile for Compatibility: Ensure the Gemfile is compatible with Rails 4.2.6 and any other dependencies. You might need to specify older versions of gems that are compatible with Ruby 2.3.8 and Rails 4.2.6.

  5. Build and Run the Docker Container:

             docker-compose build
    docker-compose up              
  6. Run Database Migrations: Once the container is up, run migrations if needed:

             docker-compose run web rake db:create db:migrate              

Considerations

  • Ruby Version: Rails 4.2.6 typically works with Ruby 2.3.x. You may need to use an older version of Ruby, like 2.3.8, which can be specified in the Dockerfile.

  • Gem Compatibility: Some gems used in Rails 4.2.6 may not be compatible with newer systems. Pinning gem versions in the Gemfile is important.

  • Security Risks: Rails 4.2.6 is no longer maintained, meaning it doesn’t receive security updates. If possible, consider upgrading to a more recent Rails version.

  • Local Development: Docker can help mitigate issues with local environment inconsistencies, ensuring that the legacy project runs consistently across different machines.

Using Docker for a Rails 4.2.6 project can streamline setting up and managing the development environment, especially with the challenges posed by running older software in modern environments.

  • Ruby on Rails
  • Docker
  • Legacy Systems
  • DevOps

Let's build something that scales.

Planning an AI product, automating a workflow, or taking a platform to production? I'd love to hear what you're building.