This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.5.2. Tagging images
The following sections provide an overview and instructions for using image tags in the context of container images for working with OpenShift Container Platform image streams and their tags.
5.2.1. Image tags 复制链接链接已复制到粘贴板!
An image tag is a label applied to a container image in a repository that distinguishes a specific image from other images in an image stream. Typically, the tag represents a version number of some sort. For example, here :v3.11.59-2 is the tag:
registry.access.redhat.com/openshift3/jenkins-2-rhel7:v3.11.59-2
registry.access.redhat.com/openshift3/jenkins-2-rhel7:v3.11.59-2
You can add additional tags to an image. For example, an image might be assigned the tags :v3.11.59-2 and :latest.
OpenShift Container Platform provides the oc tag command, which is similar to the docker tag command, but operates on image streams instead of directly on images.
5.2.2. Image tag conventions 复制链接链接已复制到粘贴板!
Images evolve over time and their tags reflect this. Generally, an image tag always points to the latest image built.
If there is too much information embedded in a tag name, like v2.0.1-may-2019, the tag points to just one revision of an image and is never updated. Using default image pruning options, such an image is never removed. In very large clusters, the schema of creating new tags for every revised image could eventually fill up the etcd datastore with excess tag metadata for images that are long outdated.
If the tag is named v2.0, image revisions are more likely. This results in longer tag history and, therefore, the image pruner is more likely to remove old and unused images.
Although tag naming convention is up to you, here are a few examples in the format <image_name>:<image_tag>:
| Description | Example |
|---|---|
| Revision |
|
| Architecture |
|
| Base image |
|
| Latest (potentially unstable) |
|
| Latest stable |
|
If you require dates in tag names, periodically inspect old and unsupported images and istags and remove them. Otherwise, you can experience increasing resource usage caused by retaining old images.
5.2.3. Adding tags to image streams 复制链接链接已复制到粘贴板!
An image stream in OpenShift Container Platform comprises zero or more container images identified by tags.
There are different types of tags available. The default behavior uses a permanent tag, which points to a specific image in time. If the permanent tag is in use and the source changes, the tag does not change for the destination.
A tracking tag means the destination tag’s metadata is updated during the import of the source tag.
Procedure
You can add tags to an image stream using the
oc tagcommand:oc tag <source> <destination>
$ oc tag <source> <destination>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to configure the
rubyimage streamstatic-2.0tag to always refer to the current image for therubyimage stream2.0tag:oc tag ruby:2.0 ruby:static-2.0
$ oc tag ruby:2.0 ruby:static-2.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow This creates a new image stream tag named
static-2.0in therubyimage stream. The new tag directly references the image id that theruby:2.0image stream tag pointed to at the timeoc tagwas run, and the image it points to never changes.To ensure the destination tag is updated when the source tag changes, use the
--alias=trueflag:oc tag --alias=true <source> <destination>
$ oc tag --alias=true <source> <destination>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Use a tracking tag for creating permanent aliases, for example, latest or stable. The tag only works correctly within a single image stream. Trying to create a cross-image stream alias produces an error.
-
You can also add the
--scheduled=trueflag to have the destination tag be refreshed, or re-imported, periodically. The period is configured globally at the system level. The
--referenceflag creates an image stream tag that is not imported. The tag points to the source location, permanently.If you want to instruct OpenShift Container Platform to always fetch the tagged image from the integrated registry, use
--reference-policy=local. The registry uses the pull-through feature to serve the image to the client. By default, the image blobs are mirrored locally by the registry. As a result, they can be pulled more quickly the next time they are needed. The flag also allows for pulling from insecure registries without a need to supply--insecure-registryto the container runtime as long as the image stream has an insecure annotation or the tag has an insecure import policy.
5.2.4. Removing tags from image streams 复制链接链接已复制到粘贴板!
You can remove tags from an image stream.
Procedure
To remove a tag completely from an image stream run:
oc delete istag/ruby:latest
$ oc delete istag/ruby:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow or:
oc tag -d ruby:latest
$ oc tag -d ruby:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow
5.2.5. Referencing images in imagestreams 复制链接链接已复制到粘贴板!
You can use tags to reference images in image streams using the following reference types.
| Reference type | Description |
|---|---|
|
|
An |
|
|
An |
|
|
A |
When viewing example image stream definitions you may notice they contain definitions of ImageStreamTag and references to DockerImage, but nothing related to ImageStreamImage.
This is because the ImageStreamImage objects are automatically created in OpenShift Container Platform when you import or tag an image into the image stream. You should never have to explicitly define an ImageStreamImage object in any image stream definition that you use to create image streams.
Procedure
To reference an image for a given image stream and tag, use
ImageStreamTag:<image_stream_name>:<tag>
<image_stream_name>:<tag>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To reference an image for a given image stream and image
shaID, useImageStreamImage:<image_stream_name>@<id>
<image_stream_name>@<id>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
<id>is an immutable identifier for a specific image, also called a digest.To reference or retrieve an image for a given external registry, use
DockerImage:openshift/ruby-20-centos7:2.0
openshift/ruby-20-centos7:2.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意When no tag is specified, it is assumed the
latesttag is used.You can also reference a third-party registry:
registry.redhat.io/rhel7:latest
registry.redhat.io/rhel7:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Or an image with a digest:
centos/ruby-22-centos7@sha256:3a335d7d8a452970c5b4054ad7118ff134b3a6b50a2bb6d0c07c746e8986b28e
centos/ruby-22-centos7@sha256:3a335d7d8a452970c5b4054ad7118ff134b3a6b50a2bb6d0c07c746e8986b28eCopy to Clipboard Copied! Toggle word wrap Toggle overflow