Docker for Rails Developers: Notes for Rails 6.1, Ruby 2.7.2

I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here.

  • p. 11 rails new myapp --skip-test. Do not add the --skip-bundle flag–it causes several steps of the new command to fail. (Notably, webpacker:install doesn’t occur.)
  • p. 19 Update the Dockerfile to get a newer version of Ruby, a recent version of yarn, and set up webpacker:
    FROM ruby:2.7.2
    
    # Ensure latest packages for Yarn
    RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true apt-key add -
    RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
    
    RUN apt-get update -yqq
    RUN apt-get install -yqq --no-install-recommends nodejs yarn
    
    WORKDIR /usr/src/app
    
    COPY . .
    
    RUN bundle install
    RUN yarn install
    
  • p. 40 Modified Dockerfile after The Gemfile Caching Trick:
    FROM ruby:2.7.2
    
    # Ensure latest packages for Yarn
    RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true apt-key add - && \
        echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
        apt-get update -yqq && apt-get install -yqq --no-install-recommends \
          nodejs \
          yarn
    
    WORKDIR /usr/src/app
    
    COPY Gemfile* ./
    
    RUN bundle install
    RUN yarn install
    
    COPY . .
    
    CMD ["bin/rails", "s", "-b", "0.0.0.0"]
    
  • p. 88 In Rails JavaScript Front End with Webpacker, nothing needs to be done to install webpacker, since we installed it at the beginning. (There is no issue with the version of node, either. In fact, running the curl to get an “up-to-date” version ends up installing a deprecated version.) You do need to install the webpacker React integration, though–docker-compose run web bin/rails webpacker:install:react.
  • p. 96 Setting Up RSpec, grab a newer version of RSpec–gem 'rspec-rails', '~> 4.0.1'–per the rspec-rails installation instructions.
  • p. 96-97 I had to stop, build, and up -d --force-recreate the webpack_dev_server after doing the same for web, after installing RSpec.
  • p. 100 gem 'capybara', '~> 3.34'
6 Likes