When I ran docker ps -a
, I got
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3be2faeb751 centos:latest touch /var/log/test 2 minutes ago Exited (1) 2 minutes ago insane_kirch6
What is the name, insane_kirch6, for?
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 the exec
or rm
command.
When you want to run a command in an existing container (running or exited), you will use the "docker exec" command in which you specify the container name or id.
Examples:
Create a container named qqqq and start a process "sleep" 1 minutes, 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