Home > front end >  Build Docker image but don't save?
Build Docker image but don't save?

Time:12-25

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?

CodePudding user response:

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>.

CodePudding user response:

I guess you could use the --output option and send the image to /dev/null

 docker build --output type=tar,dest=/dev/null .
  • Related