Pry Rails on docker not working

1.3k Views Asked by At

I tried the approach with tty: true stdin_open: true inside docker-compose.yml and attaching to the container id (following http://www.chris-kelly.net/2016/07/25/debugging-rails-with-pry-within-a-docker-container/) but it just hangs.

I also tried docker-compose run --service-ports web following this article https://blog.carbonfive.com/2015/03/17/docker-rails-docker-compose-together-in-your-development-workflow/ but it also hangs the request when binding.pry

Could supervisord affect this?

Here's the Dockerfile:

FROM ruby:2.3.3

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev supervisor
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - && apt-get install -yq nodejs
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 && apt-get install yarn


RUN mkdir /example
WORKDIR /example
COPY Gemfile /example/Gemfile
COPY Gemfile.lock /example/Gemfile.lock

RUN bundle install

COPY . /example
COPY docker/supervisor.conf /etc/supervisor/conf.d/example.conf

RUN cd client-app && npm install

CMD supervisord -n

And the docker-compose.yml:

version: '3'
services:
db:
  image: postgres
web:
  build: .
  environment:
    API_HOST: http://localhost:3000/api
  volumes:
    - .:/example
  ports:
    - "3000:3000"
    - "4200:4200"
  depends_on:
    - db

And the supervisor.conf:

[program:rails]
directory=/example
command=rails server -b 0.0.0.0 -p 3000
autostart=true
autorestart=true

[program:npm]
directory=/example
command=/bin/bash -c "yarn && cd client-app && npm run docker-start"
autostart=true
autorestart=true
1

There are 1 best solutions below

0
kwerle On

(assuming you're running postgres something like docker run -d --name=postgres ...)

I would ditch compose and try

docker build -t web .
docker run --link postgres:db -it -p 3000:3000 -p 4200:4200 web

If that fails, I'd punt and

docker run --link postgres:db -it -p 3000:3000 -p 4200:4200 web bash

Then try running rails s, rails c, etc manually within the container.