mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 22:20:12 +01:00
Support for --cleanup flag
The --cleanup flag will cause watchtower to automatically remove the old image after a container is restart with a new image.
This commit is contained in:
parent
b8ba80df2d
commit
dd80aa4a0d
10 changed files with 117 additions and 7 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func watchtowerContainersFilter(c container.Container) bool { return c.IsWatchtower() }
|
||||
|
||||
func CheckPrereqs(client container.Client) error {
|
||||
func CheckPrereqs(client container.Client, cleanup bool) error {
|
||||
containers, err := client.ListContainers(watchtowerContainersFilter)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -20,6 +20,10 @@ func CheckPrereqs(client container.Client) error {
|
|||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue