How to Rename a Docker Container

  • Post author:WunderTech
  • Post published:December 23, 2023
  • Post last modified:December 22, 2023
  • Post category:Docker
  • Reading time:6 mins read

When configuring a Docker container, you have to specify a name. If you don’t, a random name will be generated and it won’t really make sense for the context of the container. In this tutorial, we’re going to look at how to rename a Docker Container.

There are technically a few different ways that you can rename a Docker Container, but the easiest way is by using the command-line interface (CLI). This allows you to run a basic command that will rename it – however if you are utilizing something like Portainer, it’ll be a lot easier.

How to Rename a Docker Container

If you’re looking to rename a Docker Container, the easiest way to do it is by using the command-line interface (assuming you have access to it). Before you do, you must ensure that you know the current name of the Docker Container.

1. Run the command below to get a list of the current Docker Containers. The last column will hold the container name.

sudo docker container ls
displaying existing containers in CLI.

2. The next thing you have to do is rename the container using the command below.

sudo docker rename [EXISTING_CONTAINER_NAME] [NEW_CONTAINER_NAME]

In this example, I will rename the wg-easy container to be called WireGuard.

sudo docker rename wg-easy wireguard
how to rename a docker container.

3. As you can see in the very last column, the name is now wireguard as opposed to wg-easy.

showing the new name.

Renaming a Container with Portainer

While using the CLI is arguably the easiest way to rename a Docker Container, you can also use a GUI like Portainer. Keep in mind that you must have Portainer installed to use this option, but it’s just as easy.

NOTE: This method will recreate the container (so you’ll have two total versions, and must delete the first when complete. If you don’t want to do this, use the CLI option above.

1. Open Portainer and select the container that you want to rename.

viewing a container in portainer.

2. After selecting the container, Stop the container, then select Duplicate/Edit.

editing an existing container.

3. Rename the container (in the Name section), then select Deploy the Container.

NOTE: Please keep in mind that this will redeploy the container and create a new instance! If you don’t want to do this, use the CLI option above.

renaming a docker container in portainer.

4. If the new container is started and working, you can select and remove the old container.

deleting a old container in portainer.

Conclusion & Final Thoughts: Renaming Docker Containers

The process to rename a Docker Container is fairly straightforward and is generally easiest through the CLI. With that said, there are people who will feel more comfortable using a GUI like Portainer, which will work as well. Keep in mind that these names are really only for vanity purposes and don’t impact the container in any way, but it is helpful to have descriptive names.

Thanks for checking out the tutorial on how to rename a Docker Container. If you have any questions, feel free to leave them in the comments!

WunderTech

Frank is an IT professional with 13+ years experience and the creator of WunderTech. He focuses on sharing his experience with others on computer hardware, servers, software, networking, and self-hosted apps. He has a BS in Computer Information Systems and an MBA. Learn more about Frank in his bio.

This Post Has One Comment

  1. xbmcnut

    Even easier with container manager. Stop the container, go to settings, rename the container, start the container. I do this everytime I update a container by appending the version number.

Comments are closed.