Menu Close

Docker – Rename the docker container name

We will help you to understand how to rename the docker container name. For this, we use “docker rename ” command.

docker rename” command renames only container name whereas docker container ID remains same.

Command:

docker rename old_container_name new_container_name

How docker rename command works ?

  • docker rename command renames the container name irrespective of container state. It means, container name can be changed whether it’s in stopped / running state.
  • You can also create containers from docker-compose up command where docker-compose reads container property from docker-compose.yaml file. Suppose, you change the container name and bring down the container by docker-compose down command and then bring up the container by docker-compose up command. After doing this, If you will check the container name, It would be having older container name. In that case, to keep the new container name, You will need to change in docker-compose.yaml file.

Example:

% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

0a83ed486b91

redis:latest

“docker-entrypoint.s…”

5 days ago

Up 13 seconds

6379/tcp

redis

Now, Rename the redis container to new_redis container name.

% docker rename redis new_redis

% docker ps
CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
0a83ed486b91redis:latest“docker-entrypoint.s…”5 days agoUp 7 minutes6379/tcpnew_redis

To learn more about docker, Please refer given below link:

https://techieindoor.com/

References:

https://en.wikipedia.org

Posted in docker

Leave a Reply

Your email address will not be published. Required fields are marked *