Hello
For experimental purposes was executed the following command:
sudo docker rmi -f ubuntu:20.04
which prints:
Untagged: ubuntu:20.04
Untagged: ubuntu@sha256:0b897358ff6624825fb50d20ffb605ab0eaea77ced0adb8c6a4b756513dec6fc
Deleted: sha256:5f5250218d28ad6612bf653eced407165dd6475a4daf9210b299fed991e172e9
Now if is executed the sudo docker ps -a
command is displayed
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
...
ed096064373f 5f5250218d28 "cat /etc/os-release" 19 hours ago Exited (0) 19 hours ago ubuntu-20.18-d-015
3bc4c52f0299 5f5250218d28 "cat /etc/os-release" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-015
8cd0502ff777 5f5250218d28 "ls -als ../etc" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-014
d3ce9a3fbd47 5f5250218d28 "ls -als /" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-013
c8889c44f3a9 5f5250218d28 "ls -als ." 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-012
1c6ff666c7ff 5f5250218d28 "ls -als /home/manueā¦" 19 hours ago Exited (2) 19 hours ago ubuntu-20.04-d-011
b5da7429b8b8 5f5250218d28 "ls -als /etc" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-010
f169712b9718 5f5250218d28 "ls -als /etc" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-009
5ea2001f47e2 5f5250218d28 "ls -als /home" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-008
cde6c940efb4 5f5250218d28 "ls -als /home/manueā¦" 19 hours ago Exited (2) 19 hours ago ubuntu-20.04-d-007
f75c3f7932cd 5f5250218d28 "ls -als ." 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-006
7d7154a21668 5f5250218d28 "cat /etc/os-release" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-005
a75b22a43af7 5f5250218d28 "echo hello" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-004
2fcfb4dea168 5f5250218d28 "cat /home/manueljorā¦" 19 hours ago Exited (1) 19 hours ago ubuntu-20.04-d-003
8c9def0115c8 5f5250218d28 "date" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-002
f2a7ad7904a8 5f5250218d28 "ls /etc" 19 hours ago Exited (0) 19 hours ago ubuntu-20.04-d-001
...
Observe the IMAGE
header value. It shows the 5f5250218d28
value where it is the first 12 characters of sha256:5f5250218d28ad6612bf653eced407165dd6475a4daf9210b299fed991e172e9
Now, I want to remove all these containers based on the Imagesās id shown in the IMAGE
header.
Thus I did do a research and I found:
Where is indicated the following command:
docker rm $(docker ps -a -q --filter "ancestor=ubuntu")
Now, just playing with the command substitution part and by applying the following variations as follows:
docker ps -aq --filter "ancestor=5f5250218d28"
docker ps -aq --filter "ancestor=sha256:5f5250218d28"
docker ps -aq --filter "ancestor=5f5250218d28ad6612bf653eced407165dd6475a4daf9210b299fed991e172e9"
docker ps -aq --filter "ancestor=sha256:5f5250218d28ad6612bf653eced407165dd6475a4daf9210b299fed991e172e9"
All of them returns nothing
Just in case if is executed
sudo docker ps -aq --filter "name=ubuntu-20.04-d-"
It prints the expected set of containerās id but not always the containers would have the same pattern name
Question
- How to remove all the containers according with the imageās id?
So I need resolve first the command substitution part about the ps -aq --filter
command
Iāve read the official documentation about:
And it seems is not possible. But I am assuming would exists a trick/smart approach
Thank You