Docker: How to Name or Rename a Container

Updated: November 9, 2021 By: A Goodman Post a comment

You can do everything you want with a Docker container just by using its ID. That being said, giving a container a meaningful and human-friendly name will make your day more joyful and convenient.

Naming

To name a Docker container, we use the –name flag when running the docker run command (a name cannot be used twice, otherwise a conflict error will occur):

Example:

docker run -d --name kindacode_example -it ubuntu sh

To verify that everything is fine, run:

docker container ls

You will get a result similar to this:

Renaming

If you don’t happy with a container’s name, you can change it:

docker rename old-name new-name

Example:

docker rename kindacode_example new_name

Do some check:

docker ps

And you will see:

Conclusion

You’ve learned how to name and rename a container in Docker. If you’d like to explore more about this awesome technology, take a look at the following articles:

You can also check out our Docker topic page for the latest tutorials, examples, tips, and tricks.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles