简体   繁体   中英

Using Pry in Rails with Docker compose

The pry gem was in the test group:

group :test do
  gem 'pry', '~> 0.12.2'
end

It was working.

I moved it the another group.

group :development, :test do
  gem 'pry', '~> 0.12.2'
end

If I execute rspec, the binding.pry works. It halts execution however if I just run docker-compose up to start the local dev env, and add binding.pry somewhere, it does not work.

I followed the link here and rebuilt the container. Started the container however, binding.pry still doesn't work. It doesn't halt execution.

Any insight would be appreciated.

Here's my docker-compose.yml

services:

# Port 3010 is used for accessing running app in test mode from selenium service.
# Shm size needed for tests: https://github.com/elgalu/docker-selenium/issues/20
  app:
    extends:
      file: common-services.yml
      service: evt_portal_app
    command: docker/wait-for-postgres.sh db docker/start-${RAILS_ENV}.sh
    shm_size: 256M
    ports:
      - "${PORT}:${SERVER_PORT}"
      - "3010:3010"
    links:
      - db
      - webpack_dev_server
    networks:
      - default

and here's my docker-compose.develop.yml

services:

# Port 3010 is used for accessing running app in test mode from selenium service.
# Shm size needed for tests: https://github.com/elgalu/docker-selenium/issues/20
  app:
    extends:
      file: common-services.yml
      service: evt_portal_app
    command: docker/start-${RAILS_ENV}.sh
    shm_size: 128M
    ports:
      - "8083:3003"
    expose:
      - "3010"
    restart: always
    mem_limit: 4g
    memswap_limit: 4g
    depends_on:
      - delayed_job
    tty: true
    stdin_open: true

Here's a picture of the attached terminal (one created using docker attach <container ID> ): 在此处输入图片说明

As you can see, the execution is not halted.

Are you running Puma? If so the pry will be stuck in a given thread and we wont be able to access it.

In config/puma.rb you will see that there is a variable to define the number of threads.

ENV.fetch("RAILS_MAX_THREADS") { 5 }

So just make sure you set RAILS_MAX_THREADS to 1.

Then attach to the container and the pry should stop there:

docker attach <container_name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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