Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active September 1, 2018 03:35
Show Gist options
  • Save YumaInaura/0c8de43e3342db53059584661d0b491e to your computer and use it in GitHub Desktop.
Save YumaInaura/0c8de43e3342db53059584661d0b491e to your computer and use it in GitHub Desktop.
Docker — Use "names generator" made by golang directly ( docker container default randomized name )

Docker — Use "names generator" made by golang directly ( docker container default randomized name )

"names generator" gives docker container default name which randomized but uniqued.

For busy people

Use binary file in this GIST repository.

$ git clone https://gist.github.com/YumaInaura/0c8de43e3342db53059584661d0b491e names-generator
$ ./names-generator/names-generator
affectionate_matsumoto
$ ./names-generator/names-generator
recursing_vaughan

( moby/LICENSE at master · moby/moby )

What is default name?

For example you can see default names in docker ps.

In below case docker contaners were named as …

  • quizzical_payne
  • sharp_pike
  • optimistic_kepler
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
dbd46a366aa3        alpine              "sleep 100"         2 seconds ago       Up 1 second                             optimistic_kepler
454ee02db352        alpine              "sleep 100"         3 seconds ago       Up 2 seconds                            sharp_pike
1d19cef9660b        alpine              "sleep 100"         4 seconds ago       Up 3 seconds                            quizzical_payne

"names generator" is made by go language

Include one humour in codes.

...
// GetRandomName generates a random name from the list of adjectives and surnames in this package
// formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random
// integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func GetRandomName(retry int) string {
begin:
	name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))])
	if name == "boring_wozniak" /* Steve Wozniak is not boring */ {
		goto begin
	}

	if retry > 0 {
		name = fmt.Sprintf("%s%d", name, rand.Intn(10))
	}
	return name
}

Example. Use names generator directly

Install

Probably it will take long time for downloading because docker/docker is large repository.

$ go get -v github.com/docker/docker/
github.com/docker/docker (download)

Move directory

$ cd $(go env GOPATH)/src/github.com/docker/docker/pkg/namesgenerator/

Run

$ go run cmd/names-generator/main.go
hungry_mccarthy
$ go run cmd/names-generator/main.go
mystifying_bhaskara

Build and run

$ go build -o ~/tmp/names-generator cmd/names-generator/main.go
$ ~/tmp/names-generator
quirky_lederberg
$ ~/tmp/names-generator
zen_torvalds

Versions

  • Docker version 18.06.0-ce, build 0ffa825
  • go version go1.10.3 darwin/amd64

Ref

Links

This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment