Quick command reference to rename a container
| Task | Command |
|---|---|
| Rename container by name | docker rename old_name new_name |
| Rename container by ID | docker rename <container_id> new_name |
| Alternative syntax | docker container rename old_name new_name |
| List containers | docker ps -a |
You can rename a Docker container using the following command:
docker rename <old_name> <new_name>This works for both running and stopped containers and does not affect the container’s state or data.
How Docker Container Naming Works
Docker assigns each container a unique ID and, if not specified, a random name. While container IDs are long and hard to remember, names make it easier to manage and interact with containers.
Container name vs ID (why naming matters)
- Container ID is unique but not user-friendly
- Container name is easier to use for commands like start, stop, and restart
- Naming containers improves readability, debugging, and automation workflows
Method 1: Rename Docker Container Using Name (Recommended)
If you already know the container name, you can rename it directly:
docker rename old_container_name new_container_nameExample:
docker rename testubuntu ubuntu-prodThis is the most commonly used and recommended approach for renaming containers.
Method 2: Rename Docker Container Using ID
You can also rename a container using its container ID:
docker rename <container_id> new_container_nameExample:
docker rename 5973788c3dca ubuntu-testThis is useful when working with scripts or when the container name is unknown.
Method 3: Rename Container Using docker container rename
Docker also provides an alternative command format:
docker container rename old_container_name new_container_nameThis works the same as docker rename and is useful when following the newer Docker CLI syntax conventions.
Common Errors and How to Fix Them
Name already in use error
Docker requires container names to be unique. If you try to rename a container to a name that already exists, you will get an error.
Example error:
Error response from daemon: Conflict. The container name "/mycontainer" is already in useSolution:
- Choose a different unique name
- Or remove/rename the existing container
You can list existing containers using docker ps:
docker ps -aRenaming running container issues
You can rename a running container, but in some cases, changes may not immediately reflect in dependent systems or scripts.
Best practice:
- Ensure no scripts or services rely on the old container name
- Restart the container if required for consistency
docker restart <container_name>You can learn more about restarting containers here:
restart docker container
Frequently Asked Questions
1. How do I rename a Docker container?
You can rename a Docker container using the docker rename command followed by the current container name or ID and the new name.2. Can I rename a running Docker container?
Yes, Docker allows you to rename a container even while it is running using the docker rename command.3. Does renaming a container affect running applications?
No, renaming a container does not affect the running application or its state. It only changes the container name.4. What happens to container ID after renaming?
The container ID remains the same after renaming. Only the container name is updated.Conclusion
Renaming Docker containers is a simple but important task for better container management. By using clear naming conventions and the appropriate commands, you can improve readability, debugging, and automation across your Docker environments.
If you're working with multiple containers, you may also find it useful to
stop all docker containers or
remove unused containers for better resource management.
Official Documentation
For more details, refer to the official documentation:









