Docker

How to Set a Default Docker Container Name

Containers are created by using Docker which allows users to name them by using the commands. If no name is specified by the users while running a Docker container, then it will automatically assign the name to the container. Additionally, Docker allows users to rename the container at any time.

This guide demonstrated the process of setting the default Docker container name.

How to Set a Default Docker Container Name?

To set a default container name, try out the following instructions:

  • Login to Docker by using the docker login command.
  • Run the docker ps -a command to get the names of all the available containers.
  • From there simply choose the selected one to change.
  • Execute the docker rename <old-name> <new-name> command.

Step 1: Login to Docker

Initially, execute the docker login command and login to Docker:

docker login

Step 2: List All Containers

To display all the available containers including stopped and running, execute the provided command:

docker ps -a

Here, we have selected the below-highlighted container named perk_con to which we want to rename:

Step 3: Rename Container

Now, execute the docker rename command along with the existing container name and a new name:

docker rename perk_con logitect

Here, the perk_con is the previous name of the container and logitech is the new name:

Step 4: Verification

Lastly, verify whether the container was renamed successfully or not by executing the below-mentioned command:

docker ps -a

According to the provided output, the container name has been renamed successfully:

That’s it! We have provided a method for setting the default Docker container name.

Conclusion

To set the default Docker container name, first, login to Docker by using the docker login command. Then, list all the existing containers and select one of them to which you need to change. After that, execute the docker rename <old-name> <new-name> command. This guide demonstrated the process of setting the default Docker container name.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.