Docker Rails app fails to be served - curl: (56) Recv failure: Connection reset by peer

后端 未结 2 639
-上瘾入骨i
-上瘾入骨i 2020-12-31 01:39

I build a Rails app container with the following Dockerfile:

$ cat Dockerfile
FROM ruby:2.2

MAINTAINER Luca G. Soave 

RUN apt-g         


        
相关标签:
2条回答
  • 2020-12-31 01:45

    I just flagged Mykola Gurov answer because is the right 'cause' of my issue, anyway I'd also like to add the solution I implemented to work around that cause, just for tracking pourpose.

    I modified config/boot.rb by adding default option:

    $ cat config/boot.rb
    # Set up gems listed in the Gemfile.
    ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
    
    require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
    
    ########  added lines  ########
    require 'rails/commands/server' 
    
    module Rails
      class Server
        alias :default_options_alias :default_options
        def default_options
          default_options_alias.merge!(:Host => '0.0.0.0')
        end
      end
    end
    ###############################
    

    If you don't want modify config/boot.rb, another solution could be forcing Dockerfile to bind 0.0.0.0 host as an ENTRYPOINT/CMD parameter:

    $ cat Dockerfile
    FROM ruby:2.2
    
    RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
    RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
    
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY . /usr/src/app/
    RUN bundle install
    
    EXPOSE 3000
    ENTRYPOINT ["rails", "server", "-b", "0.0.0.0"]
    
    0 讨论(0)
  • 2020-12-31 02:04

    Rails server documentation states that the server by default binds to localhost, and this usually prevents dockerized application to accept connections. Try changing it to 0.0.0.0.

    0 讨论(0)
提交回复
热议问题