Running Ruby Sinatra Inside a Docker Container Not Able to Connect (Via MAC Host) or Find Commands (In Different Scenario)

Running Ruby Sinatra inside a Docker container not able to connect (via Mac host) or find commands (in different scenario)?

Change the dockerfile to use this instead:

["bundle", "exec", "rackup", "--host", "0.0.0.0", "-p", "5000"]

Running Sinatra app inside Thread doesn't work

Finally I run the other ruby process in a Thread but from Sinatra application and it works just fine.

class App < Sinatra::Base
threads = []

threads <<
Thread.new do
Some::Other::Thing
rescue StandardError => e
$stderr << e.message
$stderr << e.backtrace.join("\n")
end

trap('INT') do
puts 'trapping'
threads.each do |t|
puts 'killing'
Thread.kill t
end
end

run!
end

And I added a control when Sinatra app is exited also kill the open thread.

How to access Sinatra port using Docker with docker-compose run

When running an app with docker-compose run, service ports will not be mapped. This is by design, because run is meant for one-off tasks and not for booting the whole compose stack.

See documentation here:

https://docs.docker.com/compose/reference/run/

The second difference is that the docker-compose run command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports.

To map the ports you either need to use run with --service-ports, or add a command section to your docker-compose.yml and then use docker-compose up:

Option 1 (using run):

docker-compose run --service-ports --rm app ruby app.rb -o 0.0.0.0

Option 2 (booting the whole stack):

services:
app:
build: .
hostname: app
command: ruby app.rb -o 0.0.0.0 # <-- Add this
ports:
- "4567:4567"
...

And then:

docker-compose up

Can't access Ruby server on VM from host machine

I have the network adapter for my VM attached to NAT. I was forwarding ports 443, 22 and 80 to my VM, and accessing my server on those ports works fine. Since I was running the Ruby WEBrick server on the default port 4567, I just had to forward port 4567 from my host machine to my VM as well.

After that change, typing http://localhost:4567 into my web browser served up the content from my Ruby file.

Why is Phusion Passenger timing out after roughly 60 seconds within docker container running a ruby app?

Resolved. Turned out to be that I was running my ruby app twice. Had two instances of the run myapp command in the main app.rb and the config.ru rackup config file. Should only have one instance of that in ruby project.



Related Topics



Leave a reply



Submit