我正在尝试使其在EC2 AWS内运行dockerized项目容器,但运行却没有成功。

RoR项目取决于sidekiq,postgres和redis,因此我使用docker for rails(网络服务)和sidekiq(sidekiq服务)构建了一个“生产镜像”,目前我试图使其与docker-compose一起生产

我不得不说,本地计算机上的所有功能都可以正常工作。开发和“生产”镜像按预期工作,在EC2 AWS机器中组成“生产”镜像(Web和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>'

在我的docker-compose.yml用于EC2上的生产中,我有以下内容:
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

我被困住了,我以为这是个卷的问题,因为我还有另一个文件用于“本地生产测试镜像”并绑定(bind)了卷:sidekiq和Web服务中有-。:/ my_app,所以在生产中我删除了以下行:提及Docker Compose in Production,但出现错误production_sidekiq | No such file or directory @ rb_sysopen - /my_app/tmp/pids/sidekiq.pid
Web服务上的Puma服务器运行正常。

知道发生了什么吗?

最佳答案

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

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

07-28 01:40
查看更多