Compose: BUILD leaves old untagged image

Created on 20 May 2015  路  4Comments  路  Source: docker/compose

How to prevent BUILD command to leave old untagged image for service ?

REPOSITORY TAG IMAGE ID
service_image latest b91d042e6279

sudo docker-compose build image

REPOSITORY TAG IMAGE ID
service_image latest 9ea7fae84122
b91d042e6279

Is it expected behavior ?

kinquestion

Most helpful comment

This is no different than running docker build and overriding a tag.

I would recommend using either https://github.com/yelp/docker-custodian or https://github.com/spotify/docker-gc to cleanup old untagged images. It is not really safe for Compose to go deleting the image.

All 4 comments

These are just intermediate layers for your image, it is expected. docker build does the same thing. They will be cleaned up when the tagged images are removed.

Everytime I execute docker-compose up --build, it creates a new <none>-tagged image, with exactly the same size as the container I'm running with the tag I need.
I need to run with the --build parameter, since I'm modifying the Dockerfile or files I need in my container all the time, but for N times I run it with --build, it creates 1 image with the tag I defined, and N <none>-tagged images. Since this takes a lot of storage when running Docker Compose, I guess it's an issue, right?

This is no different than running docker build and overriding a tag.

I would recommend using either https://github.com/yelp/docker-custodian or https://github.com/spotify/docker-gc to cleanup old untagged images. It is not really safe for Compose to go deleting the image.

@dnephin While I understand it is not safe, in a development environment, it can prove extremely useful. I often end up with 10s of untagged images after many builds of an image. A docker image prune would remove other useful images that I have and do not wish to redownload later.

Would it be possible to add a flag to compose to allow compose to delete the old images when running docker-compose up -d --build such as docker-compose up -d --build --remove-old?

The documentation can explain to the user this is an unsafe flag.

Was this page helpful?
0 / 5 - 0 ratings