skip to Main Content

We’re using Docker to release our server to our different environments, but we’re also using Docker to build our server in a multi-stage docker build. When we’re just building a PR, there is no point to have docker create an image and clutter our build server with non-pushed docker images.

Is there a way to have Docker build an image, and not save it to disk, or immediately delete it afterwards?

2

Answers


  1. I’m not sure how it would be possible to create containers without saving the images on the disk. But, it is possible to delete "all images without at least one container associated to them" using prune command:

    docker image prune --all
    

    Otherwise, you have to get the ID of the newly created image (e.g. using docker-compose images -q) and then delete them using docker rmi <image_id>.

    Login or Signup to reply.
  2. I guess you could use the --output option and send the image to /dev/null

     docker build --output type=tar,dest=/dev/null .
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search