// RemoveAllContainers removes all containers in Docker Engine. // It can be used with additional force flag to remove running containers as well. func RemoveAllContainers(docker *dockerclient.DockerClient, force bool) { containers, err := docker.ListContainers(true, force, "") if err != nil { log.Fatalf("Listing containers: %s\n", err) } for _, container := range containers { fmt.Println(container.Id) docker.RemoveContainer(container.Id, force, false) } }
// RemoveDanglingImages removes dangling (untagged) images from Docker. // It can be used with additional force flag to remove those currently used as well. func RemoveDanglingImages(docker *dockerclient.DockerClient, force bool) { jsonFilters, err := createSingleValueFilter("dangling", "true") if err != nil { log.Fatalf("Encoding JSON: %s\n", err) } images, err := docker.ListImages(true, jsonFilters) if err != nil { log.Fatalf("Listing images: %s\n", err) } for _, image := range images { fmt.Println(image.Id) docker.RemoveImage(image.Id, force) } }