Skip to content

Instantly share code, notes, and snippets.

@caruccio
Created March 25, 2018 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caruccio/e7763724599583fde8724fc8701c6f33 to your computer and use it in GitHub Desktop.
Save caruccio/e7763724599583fde8724fc8701c6f33 to your computer and use it in GitHub Desktop.
Remove stale dockershim containers
#!/usr/bin/env python
## If you see messages like this on your kubelet journal:
##
## Mar 25 22:36:44 ip-10-0-3-67.ec2.internal dockerd-current[28612]: time="2018-03-25T22:36:44.419126265Z" level=error msg="Handler for GET /v1.24/containers/60532fa8184bdf41e52788194faa1253f1168e3ad4f54f7c159192fe66c4bb1d/json returned error: No such container: 60532fa8184bdf41e52788194faa1253f1168e3ad4f54f7c159192fe66c4bb1d"
##
## use this script to remove dockershim container files from /var/lib/dockershim/sandbox
import os, glob, subprocess
containers = subprocess.check_output(["docker", "ps", "--no-trunc", "-qa"]).split()
for p in glob.glob('/var/lib/dockershim/sandbox/*'):
c = p.split('/')[-1]
if c not in containers:
print 'Removing stale container', c
os.unlink(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment