"docker stack deploy": where are docker images?

Viewed 534

I created a docker compose *.yml file where I have many services with specified image tags. Then I let docker deploy a stack for me (on my local machine) with docker stack deploy -c .\my-compose-file.yml --with-registry-auth dev and it is able to run all services. When I have docker events running simultaneously, I can see image pull messages in the log, so docker pulls missing images. But when I run docker image ls -a, the pulled images are not displayed here.

So I wondering and want to know, what live cycle do the downloaded images have (will then be removed from my drive when I do docker stack rm or not), and when not, how do I clean up such images?

1 Answers

I assume you have multi-node swarm configured. In such cases, the docker image ls is running in your local machine only, while the containers from the stack are distributed across nodes. The images are pulled on the nodes that will run the container.

To get the list of the containers, you will need to go to each member of the swarm and issue the command. Easy way to do it is to use, assuming you have ssh access to the nodes with identity key:

docker node ls | cut -c 31-49 | grep -v HOSTNAME | xargs -I"SERVER" sh -c "echo SERVER; ssh SERVER /usr/local/bin/docker image ls -a"
Related