DEV Community

[Comment from a deleted post]
Collapse
 
spaceshipdev profile image
spaceshipdev • Edited

Truly eager to get this rails docker dev workflow down. I bought PragProg’s ‘Docker for Rails Developers’ some years back and still struggle to make any real repetitive progress developing in rails this way.
Perhaps some contribution here, above it’s mentioned permissions have to change, although I think this step needs to be switched otherwise the docker build command will not run.
Also; currently docker-compose up fails with

- bundler: failed to load command: rails GemNotFound public_suffix-4.0.6 in any of the sources`
Enter fullscreen mode Exit fullscreen mode

UPDATE: spent some time today getting to the bottom of this, if I may might I suggest the following edits: -
For Dockerfile

FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . .

# run this every time container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]
Enter fullscreen mode Exit fullscreen mode

For docker-compose.yml

version: "3.9"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
Enter fullscreen mode Exit fullscreen mode

Not forgetting entrypoint.sh


#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

Enter fullscreen mode Exit fullscreen mode
Collapse
 
un4uthorized profile image
Miguel

Thanks for the report, I will review the article to fix possible issues.