mirror of
https://github.com/mappu/miqt.git
synced 2025-05-07 20:40:22 +00:00
miqt-docker: auto cleanup old container versions
This commit is contained in:
parent
ded180f77b
commit
d075984e77
@ -113,6 +113,27 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Container match found - clean up older containers for the same tag
|
||||
|
||||
allContainers, err := dockerListImages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, ctr := range allContainers {
|
||||
if ctr.Repository == containerName &&
|
||||
!(ctr.Tag == dockerfileHash || ctr.Tag == "latest") {
|
||||
log.Printf("Removing previous version container %s:%s ...", containerName, ctr.Tag)
|
||||
rmCmd := dockerCommand(`image`, `rm`, containerName+`:`+ctr.Tag)
|
||||
rmCmd.Stdout = os.Stdout
|
||||
rmCmd.Stderr = os.Stderr
|
||||
err = rmCmd.Run()
|
||||
if err != nil {
|
||||
log.Printf("Warning: Failed to remove previous container: %v", err.Error())
|
||||
// log and continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Container match found - safe to run our command
|
||||
|
||||
fullCommand := []string{"run"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user