When creating a container without specifying a name, have you wondered how Docker assigns random names to it?

Primary identifier for containers is the container ID, you can do almost every operation with that but for us, for humans, using a name is less robotic. Container-based system employs randomly generated strings, consisting lowercase letters. This however have a pattern, with the first part being an adjective and the second part being the surname of a notable scientist or hacker.

container_names

Lets see how this names is generated

If you are using either of Podman or Docker, in the backend you are using component of Moby project to generate this names. Moby is an open-source project that started as a upstream for Docker but now provides the foundation for Podman or Docker. This has set of modular components for building, assembling, and shipping container-based systems.

The generator behind this is in names-generator.go file, which has two arrays, one containing adjectives and another containing names.

The GetRandomName function, as name suggest, responsible to generate this names. This function also is interesting becuase of one more thing. Whenever this generates boring_wozniak as container name, the function will discard it and generate a new name. This is possibly to pay respect to hacker and legend Steve Wozniak. This is cool!

Recently, I decided to contribute to this and added few adjustives and scientist names.

I wanted to see my contribution in action, so soon after my PR merged, I builded Moby version and wrote a script to generate containers until it gets the name that I added. It took some time and finally worked after bit of brute-forcing. It was fun!

bruteforce