snippetdockerMinor
How to get the next friendly name that Docker will assign to the container it will make?
Viewed 0 times
thecontainerdockermakenextgetnamethatwillhow
Problem
Background
When you start a Docker container as in the following example:
Docker docker automatically assigns the container an ID and a friendly name.
Docker friendly names are of the format
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
For example:
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
When you start a Docker container as in the following example:
$ docker run -ti ubuntu:latestDocker 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:latestQuestion
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:latestCode Snippets
NAME=$(curl -s https://frightanic.com/goodies_content/docker-names.php); \
docker run -ti --name $NAME --hostname $NAME ubuntu:latestContext
StackExchange DevOps Q#9810, answer score: 1
Revisions (0)
No revisions yet.