如何在Docker中使用Pry和Foreman调试Rails应用程序?

4
使用foreman,docker和pry开发ruby on rails应用程序。
已经查看了这篇文章: 如何使用Pry在Docker中调试Rails应用程序? 我通常使用 docker-compose run --service-ports web 通过 binding.pry 进行调试。
但是,在使用foreman时,docker-compose run --service-ports web 不起作用。 docker attach 可以工作,但是与 docker-compose run --service-ports web 不同,它没有什么用处。
有没有任何解决方法可以让它像使用foreman一样工作,就像 docker-compose run --service-ports web 那样?
1个回答

0

Foreman似乎是罪魁祸首。我曾经遇到过类似的问题,通过在docker-compose文件中为Procfile中描述的每个服务创建新的服务,我成功地解决了它。

之前:

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

之后:

  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

您需要将终端连接到Docker容器以进行调试:

docker attach container_id

顺便提一句:你可通过运行 docker container ls 命令来获取容器的 ID。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接