def docker_kill_and_remove(ctr_name):
try:
try:
is_running = check_output(['docker', 'top', ctr_name], stderr=DEVNULL)
except:
pass
else:
check_output(['docker', 'kill', ctr_name], stderr=STDOUT)
try:
has_image = check_output(['docker', 'images', '-q', ctr_name], stderr=DEVNULL)
assert has_image
except:
pass
else:
check_output(['docker', 'rm', ctr_name], stderr=STDOUT)
except:
logger.error('could not stop docker container:{}'.format(ctr_name))
评论列表
文章目录