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.
Table of Contents
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:
- How to Delete Docker Images on your System
- How to Get the Size of a Docker Image
- Docker: Execute Commands inside a Running Container
- Installing Docker on Ubuntu 21.04, 21.10, and 20.04
- Using Docker Compose to speed up WordPress development
You can also check out our Docker topic page for the latest tutorials, examples, tips, and tricks.