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.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

3 thoughts on “How to Name or Rename Docker Containers”

  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.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.