Rails码头集装箱在不知不觉中被杀死

时间:2018-11-09 08:07:34

标签: ruby-on-rails docker redis docker-compose

我正在使用docker-compose up运行Rails + MySQL + Redis。但是,我不知道为什么我的Rails容器将运行30秒然后被杀死。

这是我的 docker-compose.yml

version: '2'
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=pubsub_1_development
      - MYSQL_USER=appuser
      - MYSQL_PASSWORD=password
    ports:
      - "3307:3306"

  redis:
    image: 'redis:4.0-alpine'
    ports:
      - '6379:6379'

  app:
    image: pubsub_1:0.0.1
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - ".:/pubsub_1"
    ports:
      - "3001:3000"
    depends_on:
      - db
      - redis
    links:
      - db
      - redis
    environment:
      DB_USER: root
      DB_NAME: pubsub_1_development
      DB_PASSWORD: password
      DB_HOST: db

我注意到日志中有一些错误,但是我不确定在哪里解决此问题。

app_1    | => Booting Puma
app_1    | => Rails 5.1.6 application starting in development
app_1    | => Run `rails server -h` for more startup options
app_1    | Puma starting in single mode...
app_1    | * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
app_1    | * Min threads: 5, max threads: 5
app_1    | * Environment: development
app_1    | * Listening on tcp://0.0.0.0:3000
app_1    | Use Ctrl-C to stop
app_1    | Started GET "/" for 172.19.0.1 at 2018-11-09 07:47:35 +0000
app_1    | Cannot render console from 172.19.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
app_1    |    (0.6ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
app_1    |    (0.6ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
app_1    | Processing by HomeController#index as HTML
app_1    |   User Load (0.6ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
app_1    |   Rendering home/index.html.erb within layouts/application
app_1    |   Event Load (0.6ms)  SELECT `events`.* FROM `events` WHERE `events`.`user_id` = 1
app_1    |   Rendered home/index.html.erb within layouts/application (15.4ms)
app_1    | Completed 200 OK in 1266ms (Views: 1165.0ms | ActiveRecord: 5.3ms)
app_1    |
app_1    |
app_1    | Started GET "/cable" for 172.19.0.1 at 2018-11-09 07:47:39 +0000
app_1    | Cannot render console from 172.19.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
app_1    | Started GET "/cable/" [WebSocket] for 172.19.0.1 at 2018-11-09 07:47:39 +0000
app_1    | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
app_1    |   User Load (1.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
app_1    | Registered connection (Z2lkOi8vcHVic3ViMS9Vc2VyLzE)
app_1    | #<Thread:0x00007f2af4029e70@/usr/local/bundle/gems/actioncable-5.1.6/lib/action_cable/subscription_adapter/redis.rb:144 run> terminated with exception (report_on_exception is true):
app_1    | /usr/local/lib/ruby/2.5.0/socket.rb:1213:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)
app_1    | Exiting

这是全面的log file https://gist.github.com/fifiteen82726/308fcfd3b016f20de66e1b857d997d15

1 个答案:

答案 0 :(得分:0)

好像您的Rails App试图在localhost上连接Redis的地方(Redis不可用)。似乎这样会导致整个应用程序服务停止。代替localhost,它应在应用程序的配置中为Redis使用主机名redis