Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker rename Command

Docker rename Command

Docker Command ReferenceDocker Command Reference


The docker rename command is used to rename an existing container. It allows you to change a container's name directly without stopping or deleting it.

Syntax

docker rename <当前容器名称或ID> <新容器名称>

Description of commonly used parameters:

Example

1. Rename a container

Suppose there is a running container named my_old_container that you want to rename 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 confirm with the following command:



docker ps -a

2. Rename using the container ID

If you do not know the container's name but know its ID, you can use the ID to rename it. For example:



docker rename 123abc456def my_new_container

Likewise, 123abc456def is the container ID; after renaming you can check with docker ps -a.

** 3. Check for duplicate names**

If the name you try to use is already taken by another container, Docker returns 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 that case, first rename or remove the container named existing_container_name, then proceed.


Docker Command ReferenceDocker Command Reference