Use case for docker image rm --no-prune

How do I use the --no-prune option in docker image rm


It’s useful if intermediate images of the final image stiff have a use.

For example, if you’ve got an image you don’t want to keep, because, say, something systemic broke a docker build command, like a network issue caused the wrong things to get downloaded inside, but you don’t want to lose all the steps up to that point because that take 3 hours to run, you delete the image with --no-prune and re-run the build.

As to how, it’s just docker rmi --no-prune IMAGE

Thanks for the clarification.


Hi all,

[root@pnl-z840-2 ~]# images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              783686387b48        9 hours ago         27.2GB
centos              7.5.1804            cf49811e3cdb        23 months ago       200MB

[root@pnl-z840-2 ~]# docker history 783686387b48
IMAGE               CREATED             CREATED BY                                      SIZE                                        COMMENT
783686387b48        9 hours ago         /bin/sh -c wget…   3.57GB                        
6cf944031d0d        9 hours ago         /bin/sh -c git clone --recurse-submodules ht…   452MB                         
e921d070f89f        10 hours ago        /bin/sh -c ln -sf /usr/share/zoneinfo/Americ…   23GB                          
ffe1a55bf390        11 hours ago        /bin/sh -c #(nop) COPY file:3f1ef3035af09205…   44B                           
520fca8222c3        11 hours ago        /bin/sh -c #(nop) COPY file:22d1a2d55f31852a…   1.35kB                        
95c54d484b2e        11 hours ago        /bin/sh -c #(nop) COPY file:6f5d6895c0a1d576…   103B                          
beec98a3829a        11 hours ago        /bin/sh -c #(nop)  ENV LANG=en_US.UTF-8         0B                            

Will the --no-prune option be helpful in deleting just the top 783686387b48? I tried docker rmi 783686387b48 and it removed my whole image :frowning:


I realized the answer to my question to be yes :slight_smile: It was good to discover this thread. Moving forward, I shall be able to manage my containers more efficiently. Thank you!