Skip to content

Instantly share code, notes, and snippets.

@cambierr
Created February 23, 2018 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cambierr/c4de6e84becd01caf6feb7b8ee364a08 to your computer and use it in GitHub Desktop.
Save cambierr/c4de6e84becd01caf6feb7b8ee364a08 to your computer and use it in GitHub Desktop.
This scripts is a temporary workaround for https://github.com/moby/moby/issues/32620
docker node ls --format '{{.ID}}' | xargs docker node inspect --format '{{.Status.Addr}}' | while read node; do
echo "Processing node $node"
ssh -n $node "docker ps -a --filter 'is-task=true' --format '{{.ID}} {{.Label \"com.docker.stack.namespace\"}}'" | while read container; do
id=$(echo $container | cut -d ' ' -f1)
stack=$(echo $container | cut -d ' ' -f2)
found=$(docker stack ls | grep $stack | wc -l)
if [ $found == "0" ]; then
echo "no stack $stack found for container $id"
ssh -n $node "docker rm -f $id"
else
echo "found stack $stack for container $id"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment