简体   繁体   English

我可以运行我的 rake 作业吗:在运行我的 rails 服务器时在同一个 docker 容器中工作?

[英]Can I run my rake jobs:work in the same docker container as I run my rails server?

My docker compose file我的 docker 撰写文件

 web:
    build: .
    command: bundle exec rails s -b 0.0.0.0 -p 3000
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    links:
      - db
      - db-test
    depends_on:
      - db
      - db-test

Then I usually login into the container with然后我通常使用

docker-compose exec web bash

and then run然后运行

rake jobs:work

Is it possible to run both things and skip the last step?是否可以同时运行这两件事并跳过最后一步?

If you have two long-running tasks you want to do on the same code base, you can run two separate containers off the same image.如果您想在同一个代码库上执行两个长时间运行的任务,则可以在同一个映像上运行两个单独的容器。 In Docker Compose syntax that would look like在 Docker 中编写如下所示的语法

version: '3'
services:
  db: { ... }
  db-test: { ... }
  web:
    build: .
    command: bundle exec rails s -b 0.0.0.0 -p 3000
    ports:
      - "3000:3000"
    depends_on:
      - db
      - db-test
  worker:
    build: .
    command: bundle exec rake jobs:work
    depends_on:
      - db
      - db-test

Running multiple tasks in one container is kind of tricky and isn't usually recommended.在一个容器中运行多个任务有点棘手,通常不推荐。 The form you arrived on in comments, for example, launches the Rails server as a background task, and then makes the worker the main container process;例如,您在评论中到达的表单将 Rails 服务器作为后台任务启动,然后将 worker 设为主容器进程; if for some reason the main Rails application dies, Docker won't notice this, and if the worker dies, it will take the Rails application with it.如果由于某种原因主 Rails 应用程序死亡,Docker 不会注意到这一点,如果工作人员死亡,它将带上 Rails 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在rails应用程序中运行rake任务 - How do I run rake tasks within my rails application Rails:我可以在不同的服务器上运行后台作业吗? - Rails: Can I run backgrounds jobs in a different server? 不确定为什么我不能运行Rails服务器 - Not sure why I can't run my rails server 运行Rails服务器时出现NameError - NameError when I run my rails server 延迟的工作:无法执行耙工作:工作 - Delayed Jobs: can't run rake jobs:work 如何在Rails应用程序中运行Rails G模型/ Rake db:migrate - How do I run rails g model / rake db:migrate within my rails application 我可以同时运行一个Rails Server并通过终端向我的Rails Project键入命令吗? - Could I run a Rails Server and type commands to my Rails Project through terminal at the same time? 我可以在同一服务器上运行Rails 2和Rails 3应用程序吗? - Can I run a Rails 2 and a Rails 3 applications on the same server? Rails - 我可以运行rake资产:在生产服务器上预编译,而生产应用程序仍在运行吗? - Rails - Can I run rake assets:precompile on production server, while the production app is still running? 我可以在不运行Rails应用程序的rake命令的情况下运行Solr服务器吗? - Can I run Solr server without running rake command for rails application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM