docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d1e6c4dde9c fc23c99c5777 "entry.sh init" 45 seconds ago Up 44 seconds Dave-0000863x5o8rs
16ef58de3f35 fc23c99c5777 "entry.sh init" About a minute ago Up About a minute Dave-000085nktqvy0
6c92bd119be7 fc23c99c5777 "entry.sh init" About a minute ago Up About a minute Dave-000085brfoc7a
4da853f8f67c fc23c99c5777 "entry.sh init" 2 minutes ago Up 2 minutes Dave-000084ud02iu8
7fa273f30533 fc23c99c5777 "entry.sh init" 3 minutes ago Up 3 minutes Dave-000084be142eo
5c517f926f9f fc23c99c5777 "entry.sh init" 3 minutes ago Up 3 minutes Dave-000083swh54zl
ea7e9f9843b6 fc23c99c5777 "entry.sh init" 4 minutes ago Up 4 minutes Dave-000083b1da2s0
6d1e6c4dde9c fc23c99c5777 "entry.sh init" 45 seconds ago Up 44 seconds Dave-0000863x5o8rs
16ef58de3f35 fc23c99c5777 "entry.sh init" About a minute ago Up About a minute Dave-000085nktqvy0
6c92bd119be7 fc23c99c5777 "entry.sh init" About a minute ago Up About a minute Dave-000085brfoc7a
4da853f8f67c fc23c99c5777 "entry.sh init" 2 minutes ago Up 2 minutes Dave-000084ud02iu8
7fa273f30533 fc23c99c5777 "entry.sh init" 3 minutes ago Up 3 minutes Dave-000084be142eo
5c517f926f9f fc23c99c5777 "entry.sh init" 3 minutes ago Up 3 minutes Dave-000083swh54zl
ea7e9f9843b6 fc23c99c5777 "entry.sh init" 4 minutes ago Up 4 minutes Dave-000083b1da2s0
I want to grab just the container name, in order to do some scripting.
Ordinarily, I'd just use awk as per this: -
docker ps -a | awk '{print $11}'
a
a
Dave-000085brfoc7a
Dave-000084ud02iu8
Dave-000084be142eo
Dave-000083swh54zl
Dave-000083b1da2s0
a
a
Dave-000085brfoc7a
Dave-000084ud02iu8
Dave-000084be142eo
Dave-000083swh54zl
Dave-000083b1da2s0
Guess what ?
Docker has a better way ..... here's --filter
docker ps --filter name='Dave'
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d1e6c4dde9c fc23c99c5777 "entry.sh init" 4 minutes ago Up 4 minutes Dave-0000863x5o8rs
16ef58de3f35 fc23c99c5777 "entry.sh init" 5 minutes ago Up 5 minutes Dave-000085nktqvy0
6c92bd119be7 fc23c99c5777 "entry.sh init" 5 minutes ago Up 5 minutes Dave-000085brfoc7a
4da853f8f67c fc23c99c5777 "entry.sh init" 6 minutes ago Up 6 minutes Dave-000084ud02iu8
7fa273f30533 fc23c99c5777 "entry.sh init" 7 minutes ago Up 7 minutes Dave-000084be142eo
5c517f926f9f fc23c99c5777 "entry.sh init" 7 minutes ago Up 7 minutes Dave-000083swh54zl
ea7e9f9843b6 fc23c99c5777 "entry.sh init" 8 minutes ago Up 8 minutes Dave-000083b1da2s0
But, hang on, all that's done is filter by name .... we want JUST the name column to appear - here's --format
docker ps --filter name='Dave*' --format {{.Names}}
Dave-0000863x5o8rs
Dave-000085nktqvy0
Dave-000085brfoc7a
Dave-000084ud02iu8
Dave-000084be142eo
Dave-000083swh54zl
Dave-000083b1da2s0
Dave-000085nktqvy0
Dave-000085brfoc7a
Dave-000084ud02iu8
Dave-000084be142eo
Dave-000083swh54zl
Dave-000083b1da2s0
That's the ticket ....
Now we can get really purty: -
docker ps --filter name='Dave*' --format "My name is {{.Names}} and I have been {{.Status}}"
My name is Dave-000083b1da2s0 and I have been Up About an hour
With thanks to this: -