How to assign a name to running container in docker?
Asked Answered
B

1

22

I have created container from particular image using command:

$ docker run -d -P selenium/hub

running container status is below:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED                    STATUS              PORTS                     NAMES
345df9ed5b47        selenium/hub        "/opt/bin/entry_point"   5 seconds ago              Up 4 seconds        0.0.0.0:32768->4444/tcp   clever_williams

Here default name is "clever_williams" and I forgot to assign new name to it I need to change default name to running container so how can I do that?

Brockwell answered 9/11, 2016 at 6:11 Comment(2)
If you are really struck, you may wipe it out and run again within seconds with new name.Meaningless
I can do that, but I want to know how to do that while containers are running!Brockwell
J
44

Check the docker rename command, it works for either a running or stopped container, the pattern is:

docker rename old_name new_name

Therefore according with your provided data it can be:

docker rename clever_williams new_name

(This is for docker 1.10+, from PR 8570)

Johnston answered 9/11, 2016 at 7:37 Comment(4)
For the audience, this command works for a container stopped too.Rettke
Just in case to avoid confusions for the audience - I think the correct command to show is docker rename clever_williams new_name, old name to new name - but you are using the container's id as the first argument. It is not reflected in the current docker rename reference documentation. As I see your answer was written at 2016 ... I am assuming the doc was updated.Rettke
@ManuelJordan true, don't hesitate to edit this answer with your update.Johnston
Thanks to you for the confirmation and green light to edit! :)Rettke

© 2022 - 2024 — McMap. All rights reserved.