Sobes.tech
Junior

How can you rename an image in Docker?

sobes.tech AI

Answer from AI

It is not possible to rename an existing image in Docker. Instead, you can create a new tag for the existing image, which will look like a new name.

This is done using the docker tag command:

# Syntax of the docker tag command
# docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

docker tag old_image_name:latest new_image_name:latest

After executing this command, the image with the identifier old_image_name:latest will also be available under the name new_image_name:latest. The old name will be preserved.

To "rename" the image in the sense of removing the old name, you need to delete the old tag after creating the new one:

# Remove the old tag
docker rmi old_image_name:latest

The image will not be completely deleted if it is still referenced by at least one other tag (in this case, new_image_name:latest).

You can check the list of images with the command docker images:

docker images