spierce7
spierce7

Reputation: 15766

Build Docker image but don't save?

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?

Upvotes: 4

Views: 2820

Answers (2)

Hans Kilian
Hans Kilian

Reputation: 25632

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

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

Upvotes: 7

zoot
zoot

Reputation: 226

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

Upvotes: 0

Related Questions