Tagging an image
-
CLI Command docker tag [-f] old:tag namespace/new:tag2
-
https://github.com/jasonamyers/docker/blob/retag_manifest/cli/common.go#L65
-
Registered as CmdTag in (https://github.com/jasonamyers/docker/blob/retag_manifest/api/client/tag.go#L15))
-
which makes a post to /images/old%3Atag/tag?repo=namespace%2Fnew&tag=tag2&force=1
-
DAEMON : This route is defined by https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/local.go#L128
-
The route triggers postImagesTag in https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/image.go#L476
-
Parses the URL parameters
-
Instruction the daemon to tag the image via TagImage in https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/image.go#L476
-
The daemon.TagImage uses the repositories attribute which is defined at https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/image.go#L476 to Tag the image
-
daemon.repositories is a TagStore as defined at https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/image.go#L476 and the Tag method is defined at https://github.com/docker/docker/blob/v1.9.1/api/server/router/local/image.go#L476 but only makes a call to setLoad on the TagStore
-
TagStore.setLoad() is defined at https://github.com/docker/docker/blob/v1.9.1/graph/tags.go#L289
-
It finds the image in the tag store (e.g. old:tag)
-
Locks the tag store and set a defered unlock to make sure when the setLoad method exits the lock is removed
-
If no tag is given it uses "latest"
-
It validates that the new reponame is vaiid (e.g. namespace/new) with validateRepoName at https://github.com/docker/docker/blob/v1.9.1/graph/tags.go#L428
-
Then it validates that the new tag is valid (e.g. tag2) with ValidateTagName at https://github.com/docker/docker/blob/v1.9.1/graph/tags/tags.go#L24
-
Refreshes the tag store from disk to make sure it's valid via TagStore.reload at https://github.com/docker/docker/blob/v1.9.1/graph/tags.go#L124
-
It Normalizes the local name for the via registry.NormailzeLocalName at https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L384 by
-
split the local and remote parts of the name via loadRepositoryName at https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L248
-
this is handled by splitReposName (https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L299)) and
-
then validating both the index (https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L207)) and remote names (https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L219)) f
-
finally repoName is returned from localNameFromRemote (https://github.com/docker/docker/blob/v1.9.1/registry/config.go#L414)) which is used to return a full name that includes any registry information.
-
Next if checks to see if the repoName is already in the TagStore
-
If that it finds that repoName in the TagStore, it then checks to see if the tag exists in the store as well
-
If the repoName and the tag both exist it overwrites if force is supplied other wise it returns an Error message about not replacing it.
-
If the repoName is new it adds the repoName to the TagStore as a hashmap named repo
-
it then sets the repo[tag] to the imageID found in the first step of TagStore.setLoad()
-
Saves the tagStore with the new repo/tag
-
An HTTP 201 is returned to the CLI
-
The CLI command having not gotten an error returns the proper exit code