Docker - Containers - Name a container
By adding --name=meaningful_name to the docker run command, the name becomes more recognizable in interactive sessions as well as in the output of commands like docker ps.
There are limitations, however since container names must be unique, you cannot use deliberate naming and scale a service beyond one container.
On the Command Line or in a Dockerfile:
docker run --name=meaningful_name
For example, if we ran a container based on the nginx base image and started it like this:
docker run --name nginx -d nginx
The name would appear in the list of running containers:
docker ps
returns:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 08f333ef7216 nginx "nginx -g 'daemon off" 15 seconds ago Up 14 seconds 80/tcp, 443/tcp nginx
NOTE: While the name appears in the output of docker ps and can be used to manage the container, it will not appear in the command prompt of the container if you attach to it or in log files.
In order to accomplish that, you'll also need to assign a hostname.