In this quick guide, we will see how to rename a Docker container with ease.
Docker rename command
The docker rename command allows you to rename a container. The basic syntax for this command is as follows:
docker rename [OPTIONS] CONTAINER NEW_NAME
CONTAINER: This is the name or ID of the existing container that you wish to rename.
NEW_NAME: This is the new name you want to assign to the container.
Example
Default Container Names
docker run -d redis:latest
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1234567890ab redis:latest "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 6379/tcp ecstatic_einstein
Listing Containers
docker container ls -a
This command will present you with details like container ID, image name, status, and, importantly, the container's current name.
Renaming the Container
Docker provides a direct command to rename containers. Let's say you have a container named old_name and you want to rename it to new_name. Here's how you go about it:
docker rename old_name new_name
It's a good practice to ensure that the new name you're assigning isn't already in use by another container, to avoid naming conflicts.
One more example: To rename the existing container named springboot_old_container to springboot_new_container:docker rename springboot_old_container springboot_new_container
Verify the Rename
After renaming, it's always a good practice to verify the change:
docker container ls -a
Points to Remember
Container Status: A container can be renamed irrespective of its status – whether it's running, paused, or stopped.
Active Connections: If you're connected to a container through an interactive session and you rename it, the session will remain unaffected.
Consistency: If you have scripts or automated workflows that reference the container by its name, remember to update them after renaming to ensure continuity
Conclusion
In this guide, we saw how to use the docker rename command to rename the existing container.
Related Container Management Guides
- Docker Create Container
- Docker Stop All Containers
- Docker Remove All Stopped Containers
- Docker Start Container
- Docker Restart All Containers
- Docker Go Inside Container - The docker exec Command
- Docker List Containers
- Docker Fetching Logs from Containers
- Docker Rename Container
- Docker Remove Unused Containers
Comments
Post a Comment
Leave Comment