Docker.github.io: update compose/rails.md for current versions of Ruby and Rails

Created on 15 Sep 2020  路  2Comments  路  Source: docker/docker.github.io

File: compose/rails.md

Since the versions of ruby, rails and postgres have all been updated since this document was created, maybe this document should be updated?

Dockerfile

change

FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client

to

FROM ruby:2.7.1
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | 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 -qq && apt-get install -y nodejs postgresql-client yarn

Reason

the new Rails version uses webpacker for hot-reloading, webpacker requires yarn to be installed, use latest version of Ruby

Gemfile

change
gem 'rails', '~>5'
to
gem 'rails', '~> 6.0.3', '>= 6.0.3.3'

Reason

the latest Rails version is 6+

docker-compose.yml

  1. in db service under volumes: change
    - ./tmp/db:/var/lib/postgresql/data
    to
    - postgres:/var/lib/postgresql/data

  2. add volumes: section at root level of file

volumes:
  postgres:
  1. in web service add a links: section
    links:
      - db

Reason

1 & 2 - the newer postgres when running in docker has problems with file system due to permissions problems
3 - container doesn't know where to look for the database

Most helpful comment

Hi! I was just trying to use the tutorial and was unable to complete it because of the yarn dependency. I was able to find information from a couple of places to resolve it but thought I would add a gentle reminder to please update it soon. Thank you!

All 2 comments

Thanks @rcaf-anthony for all the suggestions. We'll update the page.

Hi! I was just trying to use the tutorial and was unable to complete it because of the yarn dependency. I was able to find information from a couple of places to resolve it but thought I would add a gentle reminder to please update it soon. Thank you!

Was this page helpful?
0 / 5 - 0 ratings