docker-maven-plugin icon indicating copy to clipboard operation
docker-maven-plugin copied to clipboard

Docker image is treated as dangling image despite having tags

Open jowko opened this issue 2 years ago • 2 comments

Description

We use this plugin to build docker images and we always used two tags for each build: latest and unique tag for each build. When next build will be run, previous image will be treated as dangling image even in case when new build has different second tag.

Example: Build 1:

[INFO] DOCKER> [my-test-image:latest]: Built image sha256:ce371
[INFO] DOCKER> [my-test-image:latest]: Tag with latest,v1

docker images shows:

my-test-image   v1   ce3715070a3b   14 seconds ago  963MB
my-test-image   latest   ce3715070a3b   14 seconds ago  963MB

Build 2:

[INFO] DOCKER> [my-test-image:latest]: Built image sha256:e0d3a
[INFO] DOCKER> my-test-image: Removed dangling image sha256:ce371
[INFO] DOCKER> [my-test-image:latest]: Tag with latest,v2

docker images shows:

my-test-image   v2   e0d3a0cbca94   About a minute ago   963MB
my-test-image   latest   e0d3a0cbca94   About a minute ago   963MB

Previous image was treated as dangling and was completely removed. I would expect that previous image will not be deleted if it has other tags. But it looks that this plugin either incorrectly checks if image is dangling or untags completely previous image regardless of used tags in next build (as long as at least one tag is duplicated between two builds). This causes issues in our CI/CD when more than one job was run concurrently for the same image - sometimes images were removed during jenkins build despite using unique tag as a reference everywhere we could.

I removed latest from old tags but issue still exists since latest is added as default to tags. I managed to resolve this issue after removing tags from configuration and placing tag inside name element. And also we needed to remove latest from build.

Info

  • docker-maven-plugin version : 0.39.1
  • Maven version (mvn -v) : 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
  • Docker desktop version: 20.10.8

Our previous config: config.txt Working config: config-working.txt

jowko avatar Dec 28 '22 14:12 jowko

Thanks for reporting. Cleanup is the default, but you can skip removing any previous images by setting cleanup to none:

Cleanup dangling (untagged) images after each build, including any stopped containers created from them. Also cleanup dangling images as a result of image tagging, auto-pulling a base image, or auto-pulling a cacheFrom image. Default is try, which tries to remove the old image, but doesn’t fail the build if this is not possible (e.g. because the image is still used by a running container). Other possible values are remove, if you want to fail the build, or none, to skip cleanup altogether.

from https://dmp.fabric8.io/#build-configuration

If this would solve your setup, please feel free to close this issue.

rhuss avatar Feb 14 '23 10:02 rhuss

Hello.

I managed to solve this issue by removing latest tag which was added by default. But I think that either documentation is misleading or this feature does not work corretly. Dangling image is an image which does not have any tags or child images. But in example described in first comment, you see that removed image was not dangling since it had additional tag.

So I would recommend to not remove images which have also other tags (preferred) or modify documentation which states that only dangling images are removed which is not true.

jowko avatar Feb 14 '23 20:02 jowko