用于给没有在 Dockerfile 中定义名称的镜像命名,或者用来改名。

docker image tag <imageHash> <imageName>:<imageVersion>

例如,修改 none 为 mynodejsserver:1.0:

(base) PS E:\Study\docker\dockerLearning\1 初识docker\Image&Container\python-app-starting-setup> docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
mypythoncli   1.0       36ce909907c1   2 hours ago     1.02GB
<none>        <none>    21687025c852   21 hours ago    1.13GB
mysql         8.0       6c55ddbef969   3 months ago    591MB
redis         7.2.3     e40e2763392d   13 months ago   138MB

需执行:

docker image tag 21687025c852 mynodejsserver:1.0

效果:

(base) PS E:\Study\docker\dockerLearning\1 初识docker\Image&Container\python-app-starting-setup> docker images   
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
mypythoncli      1.0       36ce909907c1   2 hours ago     1.02GB
mynodejsserver   1.0       21687025c852   21 hours ago    1.13GB
mysql            8.0       6c55ddbef969   3 months ago    591MB
redis            7.2.3     e40e2763392d   13 months ago   138MB