ruby-on-rails - 在 Docker 中启动 sidekiq 时出错:“请将 sidekiq 指向 Rails 4/5 应用程序”
问题描述
Rails 5.2、Docker Compose、Sidekiq、Redis。
这是 docker-compose 文件:
version: '3.6'
services:
redis:
image: 'redis:4.0-alpine'
command: redis-server
ports:
- '6379:6379'
volumes:
- 'redis:/data'
sidekiq:
depends_on:
- 'redis'
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- './:/app'
env_file:
- '.env'
api:
build: .
volumes:
- './:/app'
working_dir: /app
command: puma
ports:
- 3000:3000
depends_on:
- db
- redis
environment:
DATABASE_URL: postgres://postgres@db
db:
image: postgres:10.3-alpine
volumes:
redis:
postgres:
sidekiq 似乎找不到我的 Rails 应用程序。
如果我将 sidekiq 更改为这样开始:
command: bundle exec sidekiq -C config/sidekiq.yml -r /app
然后我得到这个错误:
Spring 无法找到您的 config/application.rb 文件。在 /api 中检测到您的项目根目录,因此 spring 查找 /api/config/application.rb 但它不存在。您可以通过在 config/spring.rb 中设置 Spring.application_root 来配置应用程序的根目录。
如果我改为将working_dir
设置添加到 sidekiq:
sidekiq:
depends_on:
- 'redis'
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- './:/app'
env_file:
- '.env'
working_dir:
- '/app'
然后我得到这个错误:
2019-05-27T20:27:59.770Z 1 TID-gr1e0d7n5 INFO: Booting Sidekiq 5.1.1 with redis options {:url=>"redis://redis:6379/0", :id=>"Sidekiq-server-PID-1"}
sidekiq_1 | could not connect to server: No such file or directory
sidekiq_1 | Is the server running locally and accepting
sidekiq_1 | connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
那么如何让 sidekiq 在其容器中正确启动呢?
我已经看到了这些答案,它们是相似的,但不是这个特定的错误:
解决方案
似乎sidekiq找不到Rails应用程序,通过添加'working-dir'设置修复,然后找不到postgres,所以我不得不添加环境设置以指向postgres。
最终的撰写文件是:
version: '3.6'
services:
db:
image: postgres:10.3-alpine
ports:
- '5432:5432'
redis:
image: 'redis:4.0-alpine'
command: redis-server
ports:
- '6379:6379'
volumes:
- 'redis:/data'
sidekiq:
depends_on:
- 'db'
- 'redis'
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- './:/app'
env_file:
- '.env'
working_dir: /app
environment:
DATABASE_URL: postgres://postgres@db
api:
build: .
volumes:
- './:/app'
working_dir: /app
command: puma
ports:
- 3000:3000
depends_on:
- db
- redis
environment:
DATABASE_URL: postgres://postgres@db
volumes:
redis:
postgres:
推荐阅读
- for-loop - Google Apps 脚本 - 基于电子邮件正文的标签电子邮件 [优化代码]
- javascript - $ 未定义 - 使用 jQuery 和 electron.js
- julia - Julia Pkg.update() 和 LibGit2 的麻烦
- kotlin - 如何覆盖默认的 detekt.yml?
- python - 从 MySQL 数据库中选择结果并将其分配给变量
- java - 如何使用信任库和密码指定 Kafka AdminClientConfig (Kafka Admin api)
- java - 为什么即使使用迭代器我也会得到 ConcurrentModificationException?
- vba - 使用 vba 对两个不同的工作表进行数据验证
- ecmascript-6 - 更有效地使用 Object.assign 和对象传播
- html - 将其中的所有文本大写
tags for a group of html files in side a single folder</h1> <div id="body"><p><strong>I'm currently using this code: (Linux Bash)</strong></p> <pre><code>for x in *.html; do sed -i "a/(sud