Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / Linux / How to Rename a Docker Container?

How to Rename a Docker Container?

May 13, 2020 by James Palmer

How to Rename a Docker Container?

The docker container name is a unique name identity given by the docker engine.

The docker provides the facility to rename the docker container name using the rename option.

Lets take a look at the following syntax:

# docker rename <CONTAINER-NAME | CONTAINER-NAME ID > <NEW-CONTAINER-NAME>
[email protected]:~$ sudo docker ps 
CONTAINER ID        IMAGE               COMMAND                               CREATED             STATUS              PORTS               NAMES
e3de85aaf61c        nginx               "nginx -g 'daemon ..."                1 month ago         Up 52 seconds       80/tcp              jovial_hertz

e3de85aaf61c -> The dynamically generated container id
nginx -> The Image used to invoke the container.
jovial_hertz -> A name given randomly by docker to container when it was started.

The rename command in action:

[[email protected] ~]$ sudo docker rename jovial_hertz nginx_linuxcent

We now list the output from the docker ps command

[[email protected] ~]$ [email protected]:~$ sudo docker ps 
CONTAINER ID        IMAGE               COMMAND                               CREATED             STATUS              PORTS               NAMES
e3de85aaf61c        nginx               "nginx -g 'daemon ..."                1 month ago         Up 52 seconds       80/tcp               nginx_linuxcent

You can also choose to rename a docker container while it is in running or stopped or exited state ay other states.

To Rename a docker container by identifying the container id

[[email protected] ~]$ docker ps | grep “sleep”
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
177b12c2a37c busybox “sh sleep 100″ 2 weeks ago Exited (2) 2 weeks ago eager_wiles

[[email protected] ~]$ docker rename 177b12c2a37c sleeping_geek

[[email protected] ~]$ docker ps -af status=”exited” | grep sleepi -i
177b12c2a37c busybox “sh sleep 100” 2 weeks ago Exited (2) 2 weeks ago sleeping_geek

Some common errors:

[email protected]:~$ sudo docker rename stoic_knuth nginx_linuxcent
Error response from daemon: Error when allocating new name: Conflict. The container name “/nginx-test” is already in use by container “e3de85aaf61cb0641280b91772baa3477c896fc32d604d91ad855becf56c507f”. You have to remove (or rename) that container to be able to reuse that name.
Error: failed to rename container named stoic_knuth
You cannot rename more than once container with the same name. Container name is unique bit of identity and has to be unique:

Related

Filed Under: Linux

Copyright © 2023 · News Pro Theme on Genesis Framework · WordPress · Log in