[英]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.