github.com/portworx/docker@v1.12.1/daemon/image_tag.go (about)

     1  package daemon
     2  
     3  import (
     4  	"github.com/docker/docker/image"
     5  	"github.com/docker/docker/reference"
     6  )
     7  
     8  // TagImage creates the tag specified by newTag, pointing to the image named
     9  // imageName (alternatively, imageName can also be an image ID).
    10  func (daemon *Daemon) TagImage(imageName, repository, tag string) error {
    11  	imageID, err := daemon.GetImageID(imageName)
    12  	if err != nil {
    13  		return err
    14  	}
    15  
    16  	newTag, err := reference.WithName(repository)
    17  	if err != nil {
    18  		return err
    19  	}
    20  	if tag != "" {
    21  		if newTag, err = reference.WithTag(newTag, tag); err != nil {
    22  			return err
    23  		}
    24  	}
    25  
    26  	return daemon.TagImageWithReference(imageID, newTag)
    27  }
    28  
    29  // TagImageWithReference adds the given reference to the image ID provided.
    30  func (daemon *Daemon) TagImageWithReference(imageID image.ID, newTag reference.Named) error {
    31  	if err := daemon.referenceStore.AddTag(newTag, imageID, true); err != nil {
    32  		return err
    33  	}
    34  
    35  	daemon.LogImageEvent(imageID.String(), newTag.String(), "tag")
    36  	return nil
    37  }