Container NAMES when deploying with Docker

I’ve just done my first ever Docker deployment, when i run this command to see the status of recent processes…

docker ps -a

I get this output

docker output

My question is; what are those name referring to?

Those are random names generated for each container you are running.
You can see those names at pkg/namesgenerator/names-generator.go.

// Docker, starting from 0.7.x, generates names from notable scientists and hackers.
// Please, for any amazing man that you add to the list, consider adding an equally amazing woman to it, and vice versa.
right = [...]string{ 
    // Muhammad ibn Jābir al-Ḥarrānī al-Battānī was a founding father of astronomy. https://en.wikipedia.org/wiki/Mu%E1%B8%A5ammad_ibn_J%C4%81bir_al-%E1%B8%A4arr%C4%81n%C4%AB_al-Batt%C4%81n%C4%AB
    "albattani",

    // Frances E. Allen, became the first female IBM Fellow in 1989. In 2006, she became the first female recipient of the ACM's Turing Award. https://en.wikipedia.org/wiki/Frances_E._Allen
    "allen",
...

You could have fixed name by adding --name to your docker run commands.

That practice was introduced in commit 0d29244 by Michael Crosby (crosbymichael) for docker 0.6.5 in Oct. 2013:

Add -name for docker run

Remove docker link
Do not add container id as default name
Create an auto generated container name if not specified at runtime.

Solomon Hykes (shykes) evolved that practice in docker 0.7 with commit 5d6ef317:

New collection of random names for 0.7:

mood + famous inventor.
Eg. ‘sad-tesla’ or ‘naughty-turing’

As VonC already wrote, “those are random names generated for each container you are running”. So why should you use custom names?

docker run [image-name] -[container-name]

docker run wildfly-8.1 -mywildfly

well if you want to stop/kill/run/inspect or do anything with your container, you can use your name to do so:

docker kill mydocker

docker run mydocker

Otherwise you have to do docker ps all the time and check the id (since you will not remember those made-up custom names).

One important sidenote, if you assign custom name to docker, it will be forever assigned to that specific container, which means even if you kill the container, it is not running anymore, you cannot reuse the name.
If you run

docker ps -a

you can see the old one is still there, but stopped. You can’t re-use a container name until the previous container has been removed by docker rm.

To remove containers older than some custom time, use the command:

$ docker ps -a | grep ‘weeks ago’ | awk ‘{print $1}’ | xargs
–no-run-if-empty docker rm

More on removing containers here.

Leave a Comment