In this step, you will learn how to "record" an image to a stream for a specific platform. In Docker terminology, this is typically done by tagging an existing image with a new name that includes the desired stream and potentially platform information. Tagging an image essentially creates a new pointer to an existing image layer, allowing you to refer to the same image with a different name and tag.
The basic command for tagging an image is docker tag
. The syntax is:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
SOURCE_IMAGE[:TAG]
: This is the name and optional tag of the existing image you want to tag.
TARGET_IMAGE[:TAG]
: This is the new name and optional tag you want to assign to the image. The TARGET_IMAGE
part represents the stream name.
Let's use the ubuntu
image we pulled in the previous step. We will tag it with a new stream name, for example, myubuntu
.
First, let's verify the existing ubuntu
image and its ID:
docker images ubuntu
You will see output similar to this, noting the IMAGE ID
:
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest d621e9f15c2f 2 weeks ago 72.8MB
Now, let's tag the ubuntu:latest
image with the new stream name myubuntu
and tag v1.0
:
docker tag ubuntu:latest myubuntu:v1.0
This command doesn't produce much output if successful. It simply creates the new tag.
Now, let's list the images again to see the newly tagged image:
docker images
You should now see both the original ubuntu:latest
image and the new myubuntu:v1.0
image, both pointing to the same IMAGE ID
:
REPOSITORY TAG IMAGE ID CREATED SIZE
myubuntu v1.0 d621e9f15c2f 2 weeks ago 72.8MB
ubuntu latest d621e9f15c2f 2 weeks ago 72.8MB
hello-world latest d2c94e258dcb 2 months ago 13.3kB
Notice that myubuntu:v1.0
has the same IMAGE ID
as ubuntu:latest
. This confirms that myubuntu:v1.0
is just a new reference to the same underlying image data.
While the docker tag
command itself doesn't explicitly handle platforms in the tagging process, the image itself might be built for a specific platform. When you pull an image, Docker typically pulls the image for the architecture of your system. If you need to work with images for different platforms, you would typically use tools like docker buildx
to build multi-platform images or specify the platform during the pull operation (e.g., docker pull --platform linux/amd64 ubuntu
). However, for the purpose of "recording" an existing image to a stream, the docker tag
command is the standard way to create a new reference to that image within a different stream name.