How to Name or Rename Docker Containers

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.

Read Also: How to Install Docker and Learn Basic Container Manipulation in CentOS

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
Name Docker Container
Name Docker Container

To view a list of all your docker containers, run the following command.

$ sudo docker ps
List Docker Containers
List Docker Containers

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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 Comments

Leave a Reply
  1. I have to pull images using docker pull mysql:latest, then I want to create a container using the command.

    my question is –

    docker container creates but how to add the name of a container during creating command not by using the run command and --name option?

    docker run and --name options.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.