jc00ke / guard-puma

Restart puma when files change
MIT License
50 stars 19 forks source link

Problem running guard-puma in docker #46

Open Zetrs opened 3 years ago

Zetrs commented 3 years ago

Trying to use guard-puma with docker and bridge network, like this:

networks:
  test:
    driver: bridge

services:
  rails:
...
    networks:
      - test
...

And container exiting with this error in docker logs:

"INFO - Puma starting in development environment.
INFO - Guard is now watching at '/app/bee_asr'
[1] guard(main)>
 ERROR - Guard::Puma failed to achieve its <stop>, exception was:
> [#81cc04b1fae0] Errno::EADDRNOTAVAIL: Failed to open TCP connection to localhost:9293 (Cannot assign requested address - connect(2) for "localhost" port 9293)"

Pumas config/puma.rb has this string: activate_control_app "tcp://localhost:9293" and when i connecting to container with running puma (without guard) i can reach http://localhost:9293 with curl.

$ curl http://localhost:9293?token=XXX
Unsupported action

My Guard file:

guard 'puma', :control_token => XXX do
  watch('Gemfile.lock')
  watch(%r{^app\/.+?\.ru})
end

Any ideas what it can be?

jc00ke commented 3 years ago

I'm not super familiar with Docker and its port mapping, but what happens if you explicitly map 9293:9293?

Zetrs commented 3 years ago

guard runs in the same docker container as puma, i think there is no need in any port mappings..

Zetrs commented 3 years ago

I forgot to say that it's a Windows WSL2 container. Tried to add EXPOSE 9293 and portmap 9293:9293 - same error

chriso0710 commented 2 years ago

Is there any news on this problem? I do have the same error in Docker (vscode devcontainer) on a mac.

jc00ke commented 2 years ago

To be honest, I don't even program Ruby anymore and I try to avoid Docker as much as possible. Can someone put together an extra example repo that displays the behavior?

chriso0710 commented 2 years ago

For reference and for anyone, who is looking for a solution. I solved this by using the guard-yield gem (https://github.com/guard/guard-yield) with the following Guardfile:

restart_puma = proc do
  system("pumactl -P tmp/pids/puma.pid restart")
end

guard :yield, { :run_on_modifications => restart_puma } do
    ...
end

Needs something like

pidfile 'tmp/pids/puma.pid'

in puma config

duffn commented 2 years ago

The gem works as is in Docker, though you do need to specifically disable all terminal interactions with the -i argument. https://github.com/guard/guard/wiki/Command-line-options-for-Guard#-i--no-interactions-option

For example

CMD ["bundle", "exec", "guard", "-i"]

PR to add a note to the README: https://github.com/jc00ke/guard-puma/pull/47

@jc00ke if you're looking for a new maintainer here, I could potentially help.

jc00ke commented 2 years ago

@duffn thanks for the offer and the PR! If you have specific updates you'd like to see to this project, open some issues and we can chat about it. After a few merged PRs I'd be interested in adding you as a collaborator.

@Zetrs can you try out @duffn's suggestion of using the -i flag that was merged in df43e9a and let us know how that goes for you? Thanks!