Skip to content

Commit

Permalink
backup: If container image name doesn't specify the tag, find the cor…
Browse files Browse the repository at this point in the history
…rect/used one.
  • Loading branch information
pi-anl committed Apr 27, 2021
1 parent 901c8b7 commit 84a27bf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ func backup(ID string) error {
fmt.Printf("Creating backup of %s (%s, %s)\n", conf.Name[1:], conf.Config.Image, conf.ID[:12])

paths = []string{}

var imageName = conf.Config.Image
if !strings.Contains(imageName, ":") {
// No tag on image used to start container, find the real image
images, err := cli.ImageList(ctx, types.ImageListOptions{})
if err == nil {
for _, image := range images {
if strings.Contains(conf.Image, image.ID) {
if len(image.RepoTags) > 0 {
found := image.RepoTags[0]
for _, tag := range image.RepoTags { // use closer matching tag if it exists
if strings.Contains(tag, imageName) {
found = tag
break
}
}
conf.Config.Image = found
break
}
}
}
}
}

backup := Backup{
PortMap: conf.HostConfig.PortBindings,
Config: conf.Config,
Expand Down

0 comments on commit 84a27bf

Please sign in to comment.