Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a name to running container in docker?

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?

like image 380
Pratik Patel Avatar asked Nov 09 '16 06:11

Pratik Patel


People also ask

How do you put a name on a docker container?

When a container is created using Docker, Docker provides a way to name the container using the the --name <container_name> flag. However, if no name is provided by the user while creating/running a Docker container, Docker automatically assigns the container a name.

How do you run a container and give it a name?

FreeKB - Docker Assign a name to a container using the docker run --name command. When creating a container using the docker run command, the --name option can be used to give the container a specific name. In this example, a container is created using the foo:latest image, and the name of the container will be foo.

How do I change the hostname of a running docker container?

Running the command "sudo nsenter --target 1 --uts hostname <my new hostname>" from inside the container did the trick.

Can we rename running container?

To rename docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app. After renaming a containers, confirm that it is now using the new name.


1 Answers

Check if docker rename works for a running container:

docker rename 345df9ed5b47 new_name

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

like image 176
VonC Avatar answered Oct 20 '22 12:10

VonC