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
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:
Otherwise, you have to get the ID of the newly created image (e.g. using
docker-compose images -q
) and then delete them usingdocker rmi <image_id>
.I guess you could use the
--output
option and send the image to /dev/null