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.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
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.

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.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.