Docker rename command
The `docker rename` command is used to rename an existing container. This command allows you to directly modify the container's name without stopping or removing it.
Syntax
docker rename <当前容器名称或ID> <新容器名称>
Common parameter descriptions:
- Current container name or ID: the name or ID of the existing container that needs to be renamed.
- New container name: Rename the container to the specified new name. This name must be unique and must not conflict with other running containers.
Example
1. Rename container
Suppose there is a running container named my_old_container, and you need to rename it to my_new_container:
docker rename my_old_container my_new_container
After successful execution, the container's name will become `my_new_container`. You can verify it with the following command:
docker ps -a
2. Rename using the container ID
If you don't know the container's name but know its ID, you can use the container's ID to rename it. For example:
docker rename 123abc456def my_new_container
Similarly, 123abc456def is the container's ID. After renaming, you can check it with docker ps -a.
3. Check for duplicate names
If the name you are trying to rename to is already in use by another container, Docker will return an error:
docker rename my_old_container existing_container_name
Output:
Error response from daemon: Conflict. The container name "/existing_container_name" is already in use by container "abc123". You have to remove (or rename) that container to be able to reuse that name.
In this case, you need to first rename or remove the container named `existing_container_name` before proceeding with the operation.
other extensions