When Docker containers are created, the system automatically assign a universally unique identifier (UUID) number to each container to avoid any naming conflicts and improve automation without human involvement.
In this article, we will explain how to easily identify Docker containers and name or rename containers in Linux.
By default, docker uses three ways to identify a container, namely:
- UUID long identifier e.g “21fbb152a940a37e816a442e6b09022e26b78ccd5a8eb4fcf91efeb559425c8c”.
- UUID short identifier e.g “21fbb152a940a37”.
- name e.g discourse_app.
Note that if no name is specified, by default, the the Docker daemon assigns containers a UUID long identifier; it generates a random string as a name.
How to Name a Docker Container
You can assign memorable names to your docker containers when you run them, using the
--name flag as follows. The
-d flag tells docker to run a container in detached mode, in the background and print the new container ID.
$ sudo docker run -d --name discourse_app local_discourse/app
To view a list of all your docker containers, run the following command.
$ sudo docker ps
From now on, every command that worked with a container_id can now be used with a name that you assigned, for example.
$ sudo docker restart discourse_app $ sudo docker stop discourse_app $ sudo docker start discourse_app
How to Rename a Docker Container
To rename a docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app.
$ sudo docker rename discourse_app disc_app
After renaming a containers, confirm that it is now using the new name.
$ sudo docker ps
For more information, see the docker-run man page.
$ man docker-run
That’s all! In this article, we have expalined how to name and rename Docker containers. Use the comment form below to ask any questions or to add your thoughts to this guide.