Podman build container residual problem when the build process is forced to terminate
Description
First of all, if you use Ctrl + C to force termination during the build of Podman, the containers in the build will be left in Podman, which will not only take up space but also affect the deletion of useless images.
There were forced interruptions on many previous builds, so my problem was more serious before I discovered it, otherwise one or two images that could not be deleted would not have attracted attention.
My images list:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 6b97c9f7f89f 2 days ago 1.67 GB
<none> <none> 37616f79cf88 2 days ago 992 MB
<none> <none> e5028987de23 2 days ago 1.67 GB
<none> <none> 29ebb80d809d 7 days ago 992 MB
<none> <none> 30994a0dd3f6 7 days ago 1.67 GB
<none> <none> eea90f9d3610 7 days ago 992 MB
<none> <none> e2f2eb80c593 7 days ago 1.67 GB
<none> <none> 339be923556e 7 days ago 930 MB
<none> <none> bc390bc57574 8 days ago 930 MB
docker.io/library/golang 1.18.4 e3c0472b1b62 4 weeks ago 988 MB
<none> <none> 57e0342b3532 5 weeks ago 991 MB
<none> <none> 8b5845455f80 5 weeks ago 1.67 GB
<none> <none> 803d3146f7dd 7 weeks ago 1 GB
docker.io/library/alpine latest e66264b98777 2 months ago 5.82 MB
docker.io/library/golang 1.17.5 276895edf967 7 months ago 963 MB
docker.io/library/node 16.13.0 5964aa70c11d 9 months ago 928 MB
When using podman image prune to delete useless images, there are still images left as above, then I want to delete a single image, as follows to delete the first image in the list.
podman rmi 6b97c9f7f89f
In this case, an error will be reported:
Error: 1 errors occurred:
* Image used by b63f5d5c99dd8bbb17510f58a9dfa2fe5b3a71ba57257aec6aa53c1ec4366db8: image is in use by a container
But this container does not exist using pdoman ps -a to see.
After some searching, I found that using podman ps --all --storage I can query the currently stored containers and images, which contain the containers left behind during the build process due to forced termination, as follows.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f735cc1062a7 docker.io/library/golang:1.17.5 buildah 7 weeks ago storage golang-working-container
fe95fad6d0ec docker.io/library/98ee13c4afe4a5a88fb6e3464a90ea3838e62806e9e5e025bedaaae2db25c653-tmp:latest buildah 7 weeks ago storage 8e860db1f8ded07d0d7083ee05ab5c17a7d41519b04ef3127bd3921f8b3df6ff-working-containerbf7d43b6e1de docker.io/library/b1d4f01a06501868672f31dee8be2506c18dbe938a0a12a2edb1e99fb1cb0b1d-tmp:latest buildah 7 weeks ago storage 803d3146f7ddce32b8f2e9f4f9ec7d51607f5b3ddc618758aa55634d0aa1576e-working-containere5fba2ea7216 docker.io/library/golang:1.17.5 buildah 7 weeks ago storage golang-working-container-1
7b94635d2311 docker.io/library/98ee13c4afe4a5a88fb6e3464a90ea3838e62806e9e5e025bedaaae2db25c653-tmp:latest buildah 7 weeks ago storage 8e860db1f8ded07d0d7083ee05ab5c17a7d41519b04ef3127bd3921f8b3df6ff-working-container-1
3297183ec5dd docker.io/library/b1d4f01a06501868672f31dee8be2506c18dbe938a0a12a2edb1e99fb1cb0b1d-tmp:latest buildah 7 weeks ago storage 803d3146f7ddce32b8f2e9f4f9ec7d51607f5b3ddc618758aa55634d0aa1576e-working-container-1
# There are very many more items in the back, and I have only listed some of them.
Now the task is how to solve this garbage data.
Solution
Since Podman is just a container management tool that uses buildah to build images, we can use buildah directly to clean up the containers left over from the build process, using the following method.
buildah rm --all
This method does not delete the images that are shown in podman iamges, because these images are given to podman, so you can safely delete them.