在 Docker Rails 应用上没有这样的文件或目录 @ rb_sysopen sidekiq.pid

No such file or directory @ rb_sysopen sidekiq.pid on Docker Rails app

我正在尝试使其工作 rails docker EC2 AWS 中的项目容器,但我 运行 没有成功。

RoR 项目依赖于 sidekiq、postgres 和 redis,所以我用 docker 为 rails(网络服务)和 sidekiq(sidekiq 服务)构建了一个 'production image',以及目前我试图让它与 docker-compose 一起用于生产

我不得不说,我本地机器上的一切工作正常。开发和 'production' 图像按预期工作,在 EC2 AWS 机器中合成 'production' 图像(网络和 sidekiq)时出现问题。

我收到这个错误:

production_sidekiq | No such file or directory @ rb_sysopen - /my_app/tmp/pids/sidekiq.pid
production_sidekiq | /usr/local/bundle/gems/sidekiq-4.2.10/lib/sidekiq/cli.rb:370:in `initialize'
production_sidekiq | /usr/local/bundle/gems/sidekiq-4.2.10/lib/sidekiq/cli.rb:370:in `open'
production_sidekiq | /usr/local/bundle/gems/sidekiq-4.2.10/lib/sidekiq/cli.rb:370:in `write_pid'
production_sidekiq | /usr/local/bundle/gems/sidekiq-4.2.10/lib/sidekiq/cli.rb:43:in `parse'
production_sidekiq | /usr/local/bundle/gems/sidekiq-4.2.10/bin/sidekiq:11:in `<top (required)>'
production_sidekiq | /usr/local/bundle/bin/sidekiq:23:in `load'
production_sidekiq | /usr/local/bundle/bin/sidekiq:23:in `<top (required)>'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `load'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:28:in `run'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli.rb:424:in `exec'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli.rb:27:in `dispatch'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/cli.rb:18:in `start'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/exe/bundle:30:in `block in <top (required)>'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
production_sidekiq | /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.16.6/exe/bundle:22:in `<top (required)>'
production_sidekiq | /usr/local/bin/bundle:23:in `load'
production_sidekiq | /usr/local/bin/bundle:23:in `<main>'

在我用于 EC2 生产的 docker-compose.yml 中,我有这个:

version: '3'

services:
  postgres:
    image: postgres:10.5
    environment: 
      POSTGRES_DB: my_app_production
    env_file:
      - ~/production.env

  redis:
    image: redis:4.0.11

  web:
    container_name: prod_web
    image: prod_my_app:latest
    command: bundle exec rails server -p 3000 -b '0.0.0.0' -e production
    ports:
      - '80:3000'
    depends_on:
      - postgres
      - redis
    environment: 
      RAILS_ENV: production 
      RACK_ENV: production 
      RAILS_LOG_TO_STDOUT: 'true' 
      RAILS_SERVE_STATIC_FILES: 'true' 
      EXECJS_RUNTIME: Disabled 
      SECRET_KEY_BASE: token 
      DEVISE_SECRET_KEY: token 
    env_file:
      - ~/production.env
    restart: always

  sidekiq:
    container_name: production_sidekiq
    image: prod_my_app_sidekiq:latest
    command: bundle exec sidekiq -C config/sidekiq.yml
    depends_on:
      - postgres
      - redis
    environment: 
      RAILS_ENV: production 
      RACK_ENV: production 
      RAILS_LOG_TO_STDOUT: 'true' 
      RAILS_SERVE_STATIC_FILES: 'true' 
      EXECJS_RUNTIME: Disabled 
      SECRET_KEY_BASE: token 
      DEVISE_SECRET_KEY: token 
    env_file:
      - ~/production.env
    restart: always`

并在 config/sidekiq.yml

:verbose: true
:concurrency: 1
:pidfile: ./tmp/pids/sidekiq.pid
staging:
  :concurrency: 10
production:
  :concurrency: 20
:queues:
  - default
  - mailers

我卡住了,我以为这是卷的问题,因为我有另一个文件 'local production test images' 和绑定的卷:- .:/my_app insidekiq 和网络服务,所以在生产中我删除了这行提到的 Docker Compose in Production 但我得到错误 production_sidekiq | No such file or directory @ rb_sysopen - /my_app/tmp/pids/sidekiq.pid

Web 服务上的 Puma 服务器运行正常。

知道发生了什么吗?

您不需要 pid 文件,为什么要创建一个?删除此行:

:pidfile: ./tmp/pids/sidekiq.pid