Compose: Feature Request: list all local images with docker-compose, even without containers

Created on 19 Oct 2017  路  12Comments  路  Source: docker/compose

Currently docker-compose images lists only images with created containers.

> docker-compose images --help
List images used by the created containers.
Usage: images [options] [SERVICE...]

Options:
-q     Only display IDs

I need a way to list all images on local machine relevant to docker-compose file even if they don't have containers.

I found a workaround with these steps:

> docker-compose create
> docker-compose images
> docker-compose rm

I feel there should be a way of doing it with one command. Adding a flag to images would be nice, something like -a meaning list all images

Some info:

> docker version
Client:
 Version:      17.05.0-ce
 API version:  1.29
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:06:25 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.05.0-ce
 API version:  1.29 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:06:25 2017
 OS/Arch:      linux/amd64
 Experimental: false
> docker-compose version
docker-compose version 1.15.0, build e12f3b9
docker-py version: 2.5.1
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013

Most helpful comment

# This will return no output
docker-compose build
docker-compose images
# Why!?

I would really like for this to list the images built, I don't understand why the docker-compose up -d is required to make them visible.

All 12 comments

If I'm getting the source code right, docker-compose imagesis not returning images but containers. Is that as planned or is it more kind of a bug?

@florianeichin That's a bit of a wild assumption. Have you tried running the command?

@shin- yes I did, but you getting the containers and the corresponding images, that I think is also true if I'm looking into the source code, where you get the information out of the "container.py". So therefore it's not simply possible to get the images, that are not associated to a container, no?

I think what's being requested is a way to determine which image compose would use for a particular service without needing to run that service first.

This could be useful in CI where compose is used to provide the arguments to docker-compose build and there's a need to operate on a particular image even if its container hasn't been brought up.

# This will return no output
docker-compose build
docker-compose images

# This will return a list of containers and images
docker-compose build
docker-compose up -d
docker-compose images

A workaround is to parse the output of docker-compose config, which will print the image name with any variables expanded. If there are multiple services defined then you can use yq to select a specific one.

docker-compose config | yq -r .services.${service}.image
# This will return no output
docker-compose build
docker-compose images
# Why!?

I would really like for this to list the images built, I don't understand why the docker-compose up -d is required to make them visible.

Is this being looked at all? There hasn't been an update in over 18 months.

What I enjoy about docker-compose is how nice it makes working with project specific docker, and doing things like prefixing container names with the current directory. I can get docker-compose to list images for _running containers_, but if i'm not running anything, I'd still like to see the images. Especially since docker-compose is adding the concept of a "service" and abstracting away some handling of images, it would make sense to me that docker-compose would list images for a service even if it's not running.

In my case I wanted to try out a little test app then remove images after to clear up space. I'm not sure how to accomplish this with docker-compose other than running all the services, _then_ doing docker-compose images or docker-compose ps, and manually removing the image tags.

This would be very nice to have. We build a docker-compose project in CI, and then docker save the images for offline installs. Currently on the CI server we have to actually run our application briefly (with docker-compose up --detatch) so that docker-compose images shows us the images to save.

Being able to see a list of images built without up would be a huge win in this situation.

@johnthagen We managed to parse the docker-compose config using yml parser and get the needed image names. Maybe it can work for you as a better workaround which is easier than running the dockers themselves

@slavik57 Thanks. It's a shame that with the docker-compose config you lost other metadata, such as Size, but as a way to avoid running the containers, we'll give it a shot.

@johnthagen that's true, but after getting the docker images you want, you can use the docker image inspect to get information regarding the docker images. Maybe the information you want exists there

Horribly ugly hack/workaround, but seems to be working for my needs so far...

docker image ls $(docker-compose config | yq -r '.services[].image'|while read x; do echo "--filter 'reference=${x}'"; done | xargs)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidbarratt picture davidbarratt  路  3Comments

dazorni picture dazorni  路  3Comments

maltefiala picture maltefiala  路  3Comments

dimsav picture dimsav  路  3Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  3Comments