mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00

The --cleanup flag will cause watchtower to automatically remove the old image after a container is restart with a new image.
31 lines
630 B
Go
31 lines
630 B
Go
package actions
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/CenturyLinkLabs/watchtower/container"
|
|
)
|
|
|
|
func watchtowerContainersFilter(c container.Container) bool { return c.IsWatchtower() }
|
|
|
|
func CheckPrereqs(client container.Client, cleanup bool) error {
|
|
containers, err := client.ListContainers(watchtowerContainersFilter)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(containers) > 1 {
|
|
sort.Sort(container.ByCreated(containers))
|
|
|
|
// Iterate over all containers execept the last one
|
|
for _, c := range containers[0 : len(containers)-1] {
|
|
client.StopContainer(c, 60)
|
|
|
|
if cleanup {
|
|
client.RemoveImage(c)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|