When should I use Docker's container name?
You can name your own containers with --name
when you use docker run
. If you do not provide a name, Docker will generate a random one like the one you have.
Check their documentation for naming at Legacy container links, The importance of naming
And even more importantly, you can run named containers again later with start
:
docker start --interactive named-containter
Not only for visibility, but it also can be used as container_id
,
in docker commands like start
, stop
, exec
, rm
, ...
When you want to run a command in an existing container (running or exited), you will identify the container either by name or container_id.
Examples:
Create a container named qqqq and start a process "sleep" 1 minute, and then exit.
$ docker run --name qqqq ubuntu sleep 60
Run another command in the container qqqq:
$ docker exec qqqq ps -aef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 04:21 ? 00:00:00 sleep 60
root 11 0 3 04:21 ? 00:00:00 ps -aef
Delete the container qqqq:
$ docker rm qqqq
qqqq