Search code examples
jenkinsdockerjenkins-docker

how to kill lots of docker container processes effectively and faster?


We are using Jenkins and Docker in combination.. we have set up Jenkins like master/slave model, and containers are spun up in the slave agents. Sometimes due to bug in jenkins docker plugin or for some unknown reasons, containers are left dangling.

Killing them all takes time, about 5 seconds per container process and we have about 15000 of them. Will take ~24hrs to finish running the cleanup job. How can I remove the containers bunch of them at once? or effectively so that it takes less time?

  1. Will uninstalling docker client, remove the containers?
  2. Is there a volume where these containers process kept, could be removed (bad idea)
  3. Any threading/parallelism to remove them faster? I am going to run a cron job weekly to patch these bugs, but right now I dont have whole day to get these removed.

Solution

  • Try this:

    1. Uninstall docker-engine
    2. Reboot host
    3. rm /var/lib/docker

    Rebooting effectively stops all of the containers and uninstalling docker prevents them from coming back upon reboot. (in case they have restart=always set)