Docker-maven-plugin: Remove old image if already exists when doing a docker:build

Created on 29 Jun 2016  路  13Comments  路  Source: fabric8io/docker-maven-plugin

Hello,

what's the argument to remove or not creat container ?
My command line : mvn clean package install docker:build
Thanks

Most helpful comment

docker rmi $(docker images -qa -f 'dangling=true')

wtf? Is this really the best way to not fill up a .qcow with old versions of a build you don't care about? Can't you just overwrite the old one or something? Wouldn't this kind of feature fall under "basic functionality" rather than something you have to do by hand?

All 13 comments

Sorry, didn't get the question. What is your issue ?

I want to know if there's an argument (not a command line) to remove containers after a mvn clean package install docker:build :)

docker:build doesnt create containers, only images.

docker:start creates containers and they can be removed at docker:stop after running with the option keepContainer=false. There is also a docker:remove goal for removing images.

Please let me know when and where the manual is not clear enough so that I can fix that.

Sorry,
after this command : "mvn clean package install docker:build"

I have :

hygieia-api                           latest              cb5a97d238b5        4 minutes ago       708 MB
<none>                                <none>              c117c90f967d        47 minutes ago      700.8 MB
<none>                                <none>              b7ba55168775        47 minutes ago      700.8 MB
<none>                                <none>              d98bc12b591c        47 minutes ago      700.1 MB
<none>                                <none>              fc7b12aa101b        47 minutes ago      699.3 MB
<none>                                <none>              3834b5446f96        47 minutes ago      708 MB

I do not understand why it creates images :(

These are different layers which are stacked (and the size is sum of this layer + all layers below). That is a normal Docker feature (layered filesystem), you can remove any of the layer without destroying the whole image.

Yes with this command : docker images|sed "1 d"|grep |awk '{print $3}'|sort|uniq|xargs docker rmi

thanks :)

Ok, so you mean to clean up images from a _previous_ build, right ?

BTW, the easiest way to remove dangling images is docker rmi $(docker images -qa -f 'dangling=true')

Thanks :+1:

Yeah, might make sense that if an image with the given name already exists when building that it could be (optionally) deleted.

the plugin already cleans up images from a previous build provided that image is still properly tagged/labeled.

I face the same problem after building and pushing image with same name and tag previous one is not getting deleted, wonder if there is a way for plugin to do it automatically. Otherwise the command provided by rhuss is the option docker rmi $(docker images -qa -f 'dangling=true')

mvn package dockerfile:build dockerfile:push

as you can see the new image was created with tag latest while old was left in local registry

REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
servername.azurecr.io/gs-spring-boot-docker   latest              2a356c654697        23 seconds ago      119MB
servername.azurecr.io/gs-spring-boot-docker   <none>              f8d0d3b1dd60        39 minutes ago      119MB
openjdk                                     8-jdk-alpine        224765a6bdbe        2 months ago        102MB

docker rmi $(docker images -qa -f 'dangling=true')

wtf? Is this really the best way to not fill up a .qcow with old versions of a build you don't care about? Can't you just overwrite the old one or something? Wouldn't this kind of feature fall under "basic functionality" rather than something you have to do by hand?

Execute "docker image prune" to delete old versions
See details on: https://stackoverflow.com/questions/45142528/what-is-a-dangling-image-and-what-is-an-unused-image

Was this page helpful?
0 / 5 - 0 ratings