ofelia
ofelia copied to clipboard
Does it handles replicated services?[Sorry for asking question here]
Hi, I have a replicated service (3 replicas) in my docker swarm orchestration. I wanted to know that whether there is a way to run the cron only at one container out of three in a day? I could not find anything about replicated services in does, so asked here.
Hey, Ofelia is not swarm service-aware (even if it can run a new service), it is container aware. You need to specify the name of the container to run command in.
I'm not sure how docker swarm naming containers, but probably it is has a random part in the name, so you can't really run the job-exec
.
However, if your swarm service runs some specific image, for example, my_swarm_image:latest
you can use job-run
to run a new container from that image and execute a specific commands in there, however, not sure if that would satisfy your requirements.
I guess starting a new container from that image wont help because I pass on some environment variables to stack while booting my containers through deploy stack. See below:
version: "3"
services:
production_app:
image: {id}.dkr.ecr.ap-south-1.amazonaws.com/image:latest
expose:
- 8000
deploy:
replicas: 2
command: >
sh -c "python manage.py migrate && gunicorn app.wsgi:application --workers 3 --bind 0.0.0.0:8000"
env_file:
- .prod.env
nginx:
image: {id}.dkr.ecr.ap-south-1.amazonaws.com/nginx:latest
ports:
- 80:80
These env vars are crucial for that command to succeed as they contain database creds. I dont know what would be a good way for those environments to be setup by ofelia while starting up the container. (As this env file does not lies with the server, it is on my jenkins server). I dont want to change the way I supply environment variables to my existing service.
Anyways thanks for giving some direction. Feel free to close this issue, if it is out of scope of ofelia(swarm services).