2016-04-07 17:29:18 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/reference"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TagImage creates the tag specified by newTag, pointing to the image named
|
|
|
|
// imageName (alternatively, imageName can also be an image ID).
|
|
|
|
func (daemon *Daemon) TagImage(imageName, repository, tag string) error {
|
|
|
|
imageID, err := daemon.GetImageID(imageName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
newTag, err := reference.WithName(repository)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if tag != "" {
|
|
|
|
if newTag, err = reference.WithTag(newTag, tag); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return daemon.TagImageWithReference(imageID, newTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TagImageWithReference adds the given reference to the image ID provided.
|
|
|
|
func (daemon *Daemon) TagImageWithReference(imageID image.ID, newTag reference.Named) error {
|
2016-09-15 19:37:32 -04:00
|
|
|
if err := daemon.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil {
|
2016-04-07 17:29:18 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
daemon.LogImageEvent(imageID.String(), newTag.String(), "tag")
|
|
|
|
return nil
|
|
|
|
}
|