HiveBrain v1.2.0
Get Started
← Back to all entries
snippetdockerMinor

How to get the next friendly name that Docker will assign to the container it will make?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
thecontainerdockermakenextgetnamethatwillhow

Problem

Background

When you start a Docker container as in the following example:

$ docker run -ti ubuntu:latest


Docker docker automatically assigns the container an ID and a friendly name.

Docker friendly names are of the format adjective_famousPerson.

Problem

I would like to get the friendly name that Docker will generate for the next container, so that I can assign that name to the hostname parameter of my docker run command.

For example:

$ docker run -ti --hostname docker.next_friendly_name ubuntu:latest


Question

Is there a built in way to do this with docker?

I need a friendly name that is randomly generated, but I don't want to script it up myself if there is a way to do this with Docker or even Docker Swarm or Kubernetes.

Additionally, the name of the container and the hostname of the container need to match.

Solution

As the name of the container is randomly generated you cannot get it before it's generated (by definition). You can use this service to generate random names :

NAME=$(curl -s https://frightanic.com/goodies_content/docker-names.php); \
docker run -ti --name $NAME --hostname $NAME ubuntu:latest

Code Snippets

NAME=$(curl -s https://frightanic.com/goodies_content/docker-names.php); \
docker run -ti --name $NAME --hostname $NAME ubuntu:latest

Context

StackExchange DevOps Q#9810, answer score: 1

Revisions (0)

No revisions yet.