How to Rename a Container in Docker Quickly and Easily
Use the
docker rename OLD_NAME NEW_NAME command to rename a Docker container. This changes the container's name instantly without stopping or restarting it.Syntax
The docker rename command changes the name of an existing container.
OLD_NAME: The current name or ID of the container you want to rename.NEW_NAME: The new name you want to assign to the container.
bash
docker rename OLD_NAME NEW_NAME
Example
This example shows how to rename a running container from my_old_container to my_new_container. The container keeps running during the rename.
bash
docker run -d --name my_old_container nginx # Output: container ID docker rename my_old_container my_new_container docker ps --filter "name=my_new_container"
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
<container_id> nginx "nginx -g 'daemon of…" <time_ago> Up <time> 80/tcp my_new_container
Common Pitfalls
1. Trying to rename a container to a name that already exists will fail with an error.
2. Using container ID partially or incorrectly may cause the command to fail.
3. Renaming does not change container ID or affect running state.
bash
docker rename my_new_container my_new_container # Error: Conflict. The container name "/my_new_container" is already in use by container "<id>". You have to remove (or rename) that container to be able to reuse that name.
Output
Error response from daemon: Conflict. The container name "/my_new_container" is already in use by container "<id>". You have to remove (or rename) that container to be able to reuse that name.
Quick Reference
Remember these tips when renaming Docker containers:
- Use exact current container name or full container ID.
- New name must be unique among all containers.
- Renaming does not restart or stop the container.
- Check container names with
docker ps -a.
Key Takeaways
Use
docker rename OLD_NAME NEW_NAME to rename containers instantly.The new container name must be unique and not used by any other container.
Renaming does not stop or restart the container; it only changes the name.
Check existing container names with
docker ps -a before renaming.Avoid partial or incorrect container IDs to prevent command failure.