Docker how to change repository name or rename image?

docker image tag server:latest myname/server:latest

or

docker image tag d583c3ac45fd myname/server:latest

Tags are just human-readable aliases for the full image name (d583c3ac45fd...).

So you can have as many of them associated with the same image as you like. If you don't like the old name you can remove it after you've retagged it:

docker rmi server

That will just remove the alias/tag. Since d583c3ac45fd has other names, the actual image won't be deleted.


As a shorthand you can run:

docker tag d58 myname/server:latest

Where d58 represents the first 3 characters of the IMAGE ID,in this case, that's all you need.

Finally, you can remove the old image as follows:

docker rmi server

Recently I had to migrate some images from Docker registry (docker.mycompany.com) to Artifactory (docker.artifactory.mycompany.com)

docker pull docker.mycompany.com/something/redis:4.0.10
docker tag docker.mycompany.com/something/redis:4.0.10 docker.artifactory.mycompany.com/something/redis:4.0.10
docker push docker.artifactory.mycompany.com/something/redis:4.0.10

docker tag CURRENT_IMAGE_NAME DESIRED_IMAGE_NAME

Since Docker doesn't provide an image rename capability, here is how to effectively rename a docker image in three commands:

docker pull UglyOldTag
docker tag  UglyOldTag ShinyNewTag
docker rmi  UglyOldTag

Note: This is really just adding a new tag and removing the old tag. As mentioned above, tags are actually just a mnemonic alias, or a pointer, to the image ID field. If that isn't confusing enough, the Docker API and documentation also often use "tag" to refer to the version (i.e. that part of the image name that comes after the ":", as in MyImage**:**latest).

However, typo's and mistaken names are not the only place where you might want to rename a tag. For example, if you are using Amazon's ECR, before you can check your image in, you are required to assign the full ARN as the tag. This means that your tags are big and ugly!

Note: As you look at the example below, it is useful to remember that the Amazon and DockerHub refer to each hierarchy of docker images as a "repository".

# Create the ECR 'repository' for the image 
aws ecr create-repository \
    --repository-name myFavoriteTag \
    --image-scanning-configuration scanOnPush=true \
    --region myFavoriteRegion
docker tag myFavoriteTag:latest aws_account_id.dkr.ecr.aws_region.amazonaws.com/myFavoriteTag:latest
docker push aws_account_id.dkr.ecr.aws_region.amazonaws.com/myFavoriteTag:latest

So, a quick way to clean the ugliness up is

ECR_BASE==aws_account_id.dkr.ecr.aws_region.amazonaws.com
docker pull ${ECR_BASE}/myFavoriteTag
docker tag  ${ECR_BASE}/myFavoriteTag myFavoriteTag
docker rmi  ${ECR_BASE}/myFavoriteTag
docker run myFavoriteTag

Of course, to check it back into ECR, you have to put the ugliness back on

docker tag ${ECR_BASE}/myFavoriteTag:latest