简体   繁体   English

如何使用 pry 和工头调试 docker 中的 rails 应用程序?

[英]How to debug a rails app in docker with pry and foreman?

Developing a ruby on rails app with foreman, docker, pry.与工头 docker 一起开发 ruby on rails 应用程序。

Checked this article already.已经检查了这篇文章。 How to debug a rails app in docker with pry? 如何使用 pry 调试 docker 中的 rails 应用程序?

I usually use docker-compose run --service-ports web to debug with binding.pry.我通常使用docker-compose run --service-ports web来调试 binding.pry binding.pry.

But with foreman, docker-compose run --service-ports web does not work.但是对于工头, docker-compose run --service-ports web不起作用。

docker attach works, but its not useful as docker-compose run --service-ports web docker attach工作,但它不作为docker-compose run --service-ports web

Any solution to make it work like docker-compose run --service-ports web with foreman?有什么解决方案可以让它像docker-compose run --service-ports web和工头一样工作吗?

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.我遇到了类似的问题,我设法通过在 docker-compose 文件中为 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 容器才能进行调试:

docker attach container_id

PS: You can get the container id by running docker container ls . PS:您可以通过运行docker container ls来获取容器 id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM