Docker 无法启动 rails
Docker failing to start rails
我正在尝试使用 rails 启动我的 rails 应用程序。它依赖于 redis,它似乎可以正常工作,但是当 rails 服务器启动时它失败并显示 Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
.
Docker 文件
FROM ruby:2.6.1
RUN apt-get update -yqq && \
apt-get install -yqq --no-install-recommends \
nodejs \
nano
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
RUN gem install foreman
RUN gem install rake -v 12.3.2
COPY . /usr/src/app/
CMD [ "bin/rails", "s", "-b", "0.0.0.0" ]
.docker-compose.yml
version: '3'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
env_file:
- '.env'
redis:
image: 'redis'
# volumes:
# - 'redis:/data'
rails:
depends_on:
- 'postgres'
- 'redis'
build: .
ports:
- '3000:3000'
volumes:
- '.:/usr/src/app'
env_file:
- '.env'
volumes:
redis:
postgres:
日志
rails_1 | => Booting Puma
rails_1 | => Rails 5.2.2.1 application starting in development
rails_1 | => Run `rails server -h` for more startup options
rails_1 | Exiting
rails_1 | /usr/local/lib/ruby/2.6.0/socket.rb:1213:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
rails_1 | from /usr/local/lib/ruby/2.6.0/socket.rb:1213:in `connect_nonblock'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:180:in `connect_addrinfo'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:220:in `block in connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `each'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `each_with_index'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:296:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:342:in `establish_connection'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:104:in `block in connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:299:in `with_reconnect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:103:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:372:in `ensure_connected'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:224:in `block in process'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:312:in `logging'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:223:in `process'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:123:in `call'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:1347:in `block in sadd'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:50:in `block in synchronize'
rails_1 | from /usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:50:in `synchronize'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:1346:in `sadd'
rails_1 | from /usr/local/bundle/gems/redis-namespace-1.6.0/lib/redis/namespace.rb:442:in `call_with_namespace'
rails_1 | from /usr/local/bundle/gems/redis-namespace-1.6.0/lib/redis/namespace.rb:328:in `method_missing'
rails_1 | from /usr/local/bundle/gems/resque-2.0.0/lib/resque/data_store.rb:65:in `method_missing'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:94:in `set_schedule'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:51:in `block in schedule='
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:50:in `each'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:50:in `schedule='
rails_1 | from /usr/src/app/config/initializers/resque.rb:8:in `<top (required)>'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `block in load'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:170:in `instrument'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:613:in `each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:613:in `block in <class:Engine>'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `instance_exec'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `run'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:50:in `each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `call'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `call'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:60:in `run_initializers'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/application.rb:361:in `initialize!'
rails_1 | from /usr/src/app/config/environment.rb:5:in `<top (required)>'
rails_1 | from config.ru:3:in `require_relative'
rails_1 | from config.ru:3:in `block in <main>'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
rails_1 | from config.ru:in `new'
rails_1 | from config.ru:in `<main>'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:219:in `app'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:27:in `app'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:283:in `start'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:53:in `start'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:142:in `tap'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:142:in `perform'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/command/base.rb:65:in `perform'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/command.rb:46:in `invoke'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands.rb:18:in `<top (required)>'
rails_1 | from bin/rails:4:in `require'
rails_1 | from bin/rails:4:in `<main>'
Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
您的 rails 应用程序正在尝试通过本地主机连接到 Redis,但该服务位于不同的容器中。请尝试连接到 redis:6379
。
我正在尝试使用 rails 启动我的 rails 应用程序。它依赖于 redis,它似乎可以正常工作,但是当 rails 服务器启动时它失败并显示 Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
.
Docker 文件
FROM ruby:2.6.1
RUN apt-get update -yqq && \
apt-get install -yqq --no-install-recommends \
nodejs \
nano
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
RUN gem install foreman
RUN gem install rake -v 12.3.2
COPY . /usr/src/app/
CMD [ "bin/rails", "s", "-b", "0.0.0.0" ]
.docker-compose.yml
version: '3'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
env_file:
- '.env'
redis:
image: 'redis'
# volumes:
# - 'redis:/data'
rails:
depends_on:
- 'postgres'
- 'redis'
build: .
ports:
- '3000:3000'
volumes:
- '.:/usr/src/app'
env_file:
- '.env'
volumes:
redis:
postgres:
日志
rails_1 | => Booting Puma
rails_1 | => Rails 5.2.2.1 application starting in development
rails_1 | => Run `rails server -h` for more startup options
rails_1 | Exiting
rails_1 | /usr/local/lib/ruby/2.6.0/socket.rb:1213:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
rails_1 | from /usr/local/lib/ruby/2.6.0/socket.rb:1213:in `connect_nonblock'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:180:in `connect_addrinfo'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:220:in `block in connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `each'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `each_with_index'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:218:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/connection/ruby.rb:296:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:342:in `establish_connection'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:104:in `block in connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:299:in `with_reconnect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:103:in `connect'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:372:in `ensure_connected'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:224:in `block in process'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:312:in `logging'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:223:in `process'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis/client.rb:123:in `call'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:1347:in `block in sadd'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:50:in `block in synchronize'
rails_1 | from /usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:50:in `synchronize'
rails_1 | from /usr/local/bundle/gems/redis-4.1.0/lib/redis.rb:1346:in `sadd'
rails_1 | from /usr/local/bundle/gems/redis-namespace-1.6.0/lib/redis/namespace.rb:442:in `call_with_namespace'
rails_1 | from /usr/local/bundle/gems/redis-namespace-1.6.0/lib/redis/namespace.rb:328:in `method_missing'
rails_1 | from /usr/local/bundle/gems/resque-2.0.0/lib/resque/data_store.rb:65:in `method_missing'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:94:in `set_schedule'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:51:in `block in schedule='
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:50:in `each'
rails_1 | from /usr/local/bundle/bundler/gems/resque-scheduler-bbf4930c2802/lib/resque/scheduler/scheduling_extensions.rb:50:in `schedule='
rails_1 | from /usr/src/app/config/initializers/resque.rb:8:in `<top (required)>'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `block in load'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
rails_1 | from /usr/local/bundle/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:170:in `instrument'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:613:in `each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/engine.rb:613:in `block in <class:Engine>'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `instance_exec'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `run'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:50:in `each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `call'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `call'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
rails_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/initializable.rb:60:in `run_initializers'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/application.rb:361:in `initialize!'
rails_1 | from /usr/src/app/config/environment.rb:5:in `<top (required)>'
rails_1 | from config.ru:3:in `require_relative'
rails_1 | from config.ru:3:in `block in <main>'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
rails_1 | from config.ru:in `new'
rails_1 | from config.ru:in `<main>'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:219:in `app'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:27:in `app'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app'
rails_1 | from /usr/local/bundle/gems/rack-2.0.7/lib/rack/server.rb:283:in `start'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:53:in `start'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:142:in `tap'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands/server/server_command.rb:142:in `perform'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
rails_1 | from /usr/local/bundle/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/command/base.rb:65:in `perform'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/command.rb:46:in `invoke'
rails_1 | from /usr/local/bundle/gems/railties-5.2.2.1/lib/rails/commands.rb:18:in `<top (required)>'
rails_1 | from bin/rails:4:in `require'
rails_1 | from bin/rails:4:in `<main>'
Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
您的 rails 应用程序正在尝试通过本地主机连接到 Redis,但该服务位于不同的容器中。请尝试连接到 redis:6379
。