func deleteOldContainers()

in gce-containers-startup/runtime/runtime.go [170:194]


func deleteOldContainers(dockerClient DockerApiClient, rawName string) error {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	listOpts := dockertypes.ContainerListOptions{All: true}
	containers, err := dockerClient.ContainerList(ctx, listOpts)
	if err != nil {
		return err
	}
	idsNames := containersStartedByKonlet(containers, rawName)
	if len(idsNames) == 0 {
		log.Print("No containers created by previous runs of Konlet found.\n")
		return nil
	}
	for id, name := range idsNames {
		log.Printf("Removing a container created by a previous run of Konlet: '%s' (ID: %s)\n", name, id)
		rmOpts := dockertypes.ContainerRemoveOptions{
			Force: true,
		}
		if err := dockerClient.ContainerRemove(ctx, id, rmOpts); err != nil {
			return err
		}
	}
	return nil
}