0
votes

I am using the azure devops pipeline to build a docker image for my asp.net web application. I have to use self-hosted agent as build and deployment server. After each time running the CI pipeline, new images are created and then pushed to Docker registry. now the problem is , the images which are built and saved on the agent! after a while the agent disk faces the low disk and I have to delete the old images manually. How can I delete docker images after pushing to the registry during the CI pipeline?

please check attached snapshot.enter image description here

4

4 Answers

1
votes

Run

docker rmi -f image-name 

which will forcefully remove the image after you push the image to the registry

0
votes

After you push the image to the registry add a cmd task with the command to remove the image:

docker rmi [OPTIONS] IMAGE [IMAGE...]

For example:

docker rmi test1:latest
0
votes

After pushing image add command line step to delete image:

- task: CmdLine@2
  inputs:
    script: 'docker rmi -f IMAGE:TAG' 

or more destructive

- task: CmdLine@2
  inputs:
    script: 'docker system prune -a --force' 
0
votes

How about using docker system prune. Doing this usually removes all dangling images from the system but using it with -a should take care of removing any unused images as well.

Please refer to official documentation here .