Tag the image with the specified name and store it in the local containers storage. The name is normalized according to the rules of NormalizeName.
(name string)
| 508 | // Tag the image with the specified name and store it in the local containers |
| 509 | // storage. The name is normalized according to the rules of NormalizeName. |
| 510 | func (i *Image) Tag(name string) error { |
| 511 | if strings.HasPrefix(name, "sha256:") { // ambiguous input |
| 512 | return errors.Wrap(errTagDigest, name) |
| 513 | } |
| 514 | |
| 515 | ref, err := NormalizeName(name) |
| 516 | if err != nil { |
| 517 | return errors.Wrapf(err, "normalizing name %q", name) |
| 518 | } |
| 519 | |
| 520 | if _, isDigested := ref.(reference.Digested); isDigested { |
| 521 | return errors.Wrap(errTagDigest, name) |
| 522 | } |
| 523 | |
| 524 | logrus.Debugf("Tagging image %s with %q", i.ID(), ref.String()) |
| 525 | if i.runtime.eventChannel != nil { |
| 526 | defer i.runtime.writeEvent(&Event{ID: i.ID(), Name: name, Time: time.Now(), Type: EventTypeImageTag}) |
| 527 | } |
| 528 | |
| 529 | newNames := append(i.Names(), ref.String()) |
| 530 | if err := i.runtime.store.SetNames(i.ID(), newNames); err != nil { |
| 531 | return err |
| 532 | } |
| 533 | |
| 534 | return i.reload() |
| 535 | } |
| 536 | |
| 537 | // to have some symmetry with the errors from containers/storage. |
| 538 | var errTagUnknown = errors.New("tag not known") |