This quick tutorial shows you how to rename a Docker image / container.
I’ll be using hello-world
Docker image to demonstrate the usage of each command.
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 4 months ago 13.3kB
$ docker run hello-world
Hello from Docker!
..........
......
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1972fa4393d5 hello-world "/hello" 4 seconds ago Exited (0) 4 seconds ago sad_shaw
Rename Docker Image
To rename a Docker image, use either docker tag
or docker image tag
commands.
Here you can use image name or ID as reference to the current image.
// Using Image Name
$ docker tag <OLD NAME (REPOSITORY:TAG)> <NEW NAME (REPOSITORY:TAG)>
e.g.
$ docker tag hello-world:latest hello-world:latest_renamed_using_repo_and_tag
// Using Image ID
$ docker tag <IMAGE ID> <NEW NAME (REPOSITORY:TAG)>
e.g.
$ docker tag bf756fb1ae65 hello-world:latest_renamed_using_imageId
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 4 months ago 13.3kB
hello-world latest_renamed_using_imageId bf756fb1ae65 4 months ago 13.3kB
hello-world latest_renamed_using_repo_and_tag bf756fb1ae65 4 months ago 13.3kB
Even though the image names (REPOSITORY
:TAG
) are different,
IMAGE ID
will be common among all images since this is the same image
under 3 different references.
Rename Docker Container
To rename a Docker container, use either docker rename
or docker container rename
commands.
Here you can use container ID as reference to the current container.
// Using Container Name
$ docker rename <OLD NAME> <NEW NAME>
e.g.
$ docker rename sad_shaw hello_world
// Using Container ID
$ docker rename <CONTAINER ID> <NEW NAME>
e.g.
$ docker rename 1972fa4393d5 hello_world
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1972fa4393d5 hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago hello_world
Leave a comment