mirror of
https://github.com/containers/podman.git
synced 2025-06-25 12:20:42 +08:00
podman rmi shouldn't delete named referenced images
If an image is created from another and it is deleted, only delete the actual image and not the parent images if the parent images have names/references. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #1174 Approved by: mheon
This commit is contained in:
@ -363,7 +363,7 @@ func (i *Image) Remove(force bool) error {
|
||||
}
|
||||
// Do not remove if image is a base image and is not untagged, or if
|
||||
// the image has more children.
|
||||
if (nextParent == nil && len(parent.Names()) > 0) || len(children) > 0 {
|
||||
if len(children) > 0 || len(parent.Names()) > 0 {
|
||||
return nil
|
||||
}
|
||||
id := parent.ID()
|
||||
|
@ -141,6 +141,41 @@ var _ = Describe("Podman rmi", func() {
|
||||
Expect(session.ExitCode()).To(Not(Equal(0)))
|
||||
})
|
||||
|
||||
It("podman rmi image that is created from another named imaged", func() {
|
||||
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--name", "c_test1", ALPINE, "true"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--name", "c_test2", "test1", "true"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"rm", "-a"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"rmi", "test2"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"images", "-q"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman rmi with cached images", func() {
|
||||
session := podmanTest.Podman([]string{"rmi", "-fa"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
Reference in New Issue
Block a user