I'm planning dockerize my existing Rails project.
My project has an API controller and worker to run jobs in background
Is there a way to separate my application in 3 parts using docker containers:
Eg:
I know that i can use one container for the application and another to database, but my question is about isolate the application.
Typically, your jobs will be saved to a backend- eg Redis for Sidekiq, some sql database for delayed_jobs. The actual execution of the jobs can be placed somewhere else.
In the web server's Dockerfile you might have the entry point written like this (example):
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
This runs only the web-server. To be honest, I think the "application" and the API that you're talking about should run off the same container.
For the execution of the jobs, you can use the same image, but define a different entry point. (Check out docker-compose , it's really handy)
In there, you would ask it to.. start up some workers for instance, and that command would depend on which background processing gem you chose to go with. You will also need to pass it the configuration for the database that the jobs are stored in.
An sample docker-compose file that you might write might look like this:
version: '2'
services:
redis:
image: 'redis:3.2-alpine'
command: redis-server
ports:
- 6379:6379
volumes:
- redis:/data
app:
depends_on:
- redis
- postgres (or some other db you have)
build: .
ports:
- 3000:3000
volumes:
- .:/app
sidekiq:
depends_on:
- redis
build: .
command: sidekiq -C config/sidekiq.yml.erb
volumes:
- .:/app
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.