docker ps -f health=unhealthy --format "docker restart {{.ID}}" | xargs --no-run-if-empty -t docker restart
output is :
docker restart docker restart 7c20974e2b02
7c20974e2b02
Error response from daemon: No such container: docker
Error response from daemon: No such container: restart
How do I not get the "Error response from daemon: No such container: "
Take
docker restartout of the format string; it should only be on the argument list.When you had it in both places you were passing the string
docker restartat least twice whenever xargs invoked anything at all.Alternately, consider doing this without xargs entirely. Assuming that the number of unhealthy nodes is short enough to fit on a single command line -- generally a safe assumption, since the combined environment + argument length limit is typically in the range of 128KB on modern systems: