In Docker Swarm mode, is there a way to restart a Docker service, just before it reaches a specific threshold of cpu or memory?

The story goes like this!

  1. I have used Docker Swarm mode as an orchestration tool!
  2. I have deployed my live_ofbiz service in swarm mode!
  3. Service live_ofbiz contains bloated containers, with an image of size 1.25 GB.
  4. There is some way or the other, where the container is leaking memory.
  5. I have limited the memory usage of the service to 6GB. (docker stats)docker stats
  6. With about 150 daily users on the application, the container is bound to die after 10-12 days, leaving a downtime of 2 minutes, when the memory limit capacity of 6GB is reached!

So my question is, is there any way through which I can set a threshold limit of 6GB, and in the meantime, a new container can launch itself and replace the live_ofbiz's running container (just like docker service update --image ofbiz:$SAME_OLD_IMAGE_VERSION live_ofbiz, but in an automated fashion)?

A possible solution can be adding a corn job to identify the memory limit reached, and hence triggering the update command via shell! But I would refrain from using a corn job due to some restrictions!

I'd like to know if Docker Swarm mode / Services configuration provides such a solution by default or not!

Thank you in advance! :)

1 answer

  • answered 2022-05-04 18:01 matic1123

    As far as I know, unless you have your own API/CRON/... system/application which would be monitoring and then doing the actions needed Docker Swarm does not have a way to do so. You can probably use more than one replica of the "troublesome" service and then whenever the swarm decides to .. kill the "bad" one at least one is still running so you would minimize downtime to almost 0 or 0.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum