"docker stack deploy": where are docker images?
Asked Answered
D

1

6

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?

Diadem answered 11/2, 2021 at 10:34 Comment(0)
S
1

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"
Skilled answered 22/2, 2021 at 13:6 Comment(3)
No, I observed such behavior also on a single node swarm. I deploy a stack on my local machine (only one in the swarm) and I don't see images pulled on my machine, that is what confused me.Philippopolis
You can verify if the images are on your machine by inspecting the filesystem where Docker stores the metadata of the overlay images. It's usually in /var/lib/docker/image/overlay2/ on linux machines. The docker system prune -a --volumes will delete all unused items.Skilled
Of course, images pulled during a swarm deployment will still end up in the local image chache. They will have the expected Image ID, though swarm will remove the TAG resulting in <none> beeing shown.Libyan

© 2022 - 2024 — McMap. All rights reserved.