4

Developing a ruby on rails app with foreman, docker, pry.

Checked this article already. How to debug a rails app in docker with pry?

I usually use docker-compose run --service-ports web to debug with binding.pry.

But with foreman, docker-compose run --service-ports web does not work.

docker attach works, but its not useful as docker-compose run --service-ports web

Any solution to make it work like docker-compose run --service-ports web with foreman?

Ruturaj Bisure
  • 151
  • 1
  • 13

1 Answers1

0

Foreman seems to be the culprit. I was facing a similar issue and I managed to solve it by creating new services in the docker-compose file for each service described in the Procfile.

Before:

web:
  build: .
  entrypoint: ./entrypoint-dev.sh
  command: bash -c "bundle exec foreman start -f Procfile.dev -p 3000"
  tty: true
  volumes:
  - .:/usr/src/app
  - bundle:/usr/local/bundle
  ports:
  - 3000:3000
environment:
  - RAILS_MAX_THREADS=5
  - RAILS_ENV=development
  - RACK_ENV=development
  - DATABASE_HOST=db
  - DATABASE_USER=postgres
  - DATABASE_PASSWORD=password
depends_on:
  - db
  - redis

After:

  js:
    build:
      context: "."
    tty: true
    command: "yarn build --watch"
    volumes:
      - .:/usr/src/app

  css:
    build:
      context: "."
    tty: true
    command: "yarn build:css --watch"
    volumes:
      - .:/usr/src/lazy-joker

  web:
    build: .
    entrypoint: ./entrypoint-dev.sh
    command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
    stdin_open: true
    tty: true
    volumes:
      - .:/usr/src/app
      - bundle:/usr/local/bundle
    ports:
      - 3000:3000
    environment:
      - RAILS_MAX_THREADS=5
      - RAILS_ENV=development
      - RACK_ENV=development
      - DATABASE_HOST=db
      - DATABASE_USER=postgres
      - DATABASE_PASSWORD=password
    depends_on:
      - db
      - redis
      - js
      - css

You need to attach your terminal to the docker container in order to debug:

docker attach container_id

PS: You can get the container id by running docker container ls.

betogrun
  • 93
  • 2
  • 7