docker-cleanup icon indicating copy to clipboard operation
docker-cleanup copied to clipboard

Containers getting incorrectly cleaned up?

Open mattdodge opened this issue 9 years ago • 7 comments

I'm a bit confused as to how KEEP_CONTAINERS and KEEP_CONTAINERS_NAMED are supposed to work together. We were running this docker container (using the Rancher catalog stack) with the following env vars set:

KEEP_CONTAINERS = "*:*"
KEEP_CONTAINERS_NAMED = "**None**"
KEEP_IMAGES = "/rancher"

Based on that config and the docs I would expect no containers to ever get cleaned up (each container's image should match the KEEP_CONTAINERS rule). However, we were seeing some start-once, data-only containers get cleaned up.

mattdodge avatar Jul 12 '17 15:07 mattdodge

Hi @mattdodge ! We are using pretty much the same setup and facing same kind of problems. Specifically with Jenkins stack provided by the Rancher catalog

I've checked checkPatterns func in the run.sh and from my understanding it cannot filter out and protect containers by the *:* as well as the images with tag latest as far as image names in that case are reported without :latest. busybox image used in the Jenkins stack from Rancher is a good example of that, you can try docker inspect --format='{{(index .Config.Image)}}' <jenkins-datavolume-container-id> and check the output

vi7 avatar Jul 27 '17 13:07 vi7

I believe the expected behavior is that the container will be kept if at least one of the KEEP_CONTAINERS or KEEP_CONTAINERS_NAMED conditions match. So it must be the case that either a) these containers do no match either rule, or b) there is a bug.

In your case, no containers will ever match **None**. What is the image name of the containers being destroyed?

jnjackins avatar Jul 28 '17 19:07 jnjackins

Have you run docker-cleanup with DEBUG enabled?

jnjackins avatar Jul 28 '17 19:07 jnjackins

I would also expect that to be an OR operation, that didn't seem to be the case though. Haven't run with DEBUG and I don't have the original container names but this is what it is named now so should be close. These are the details of the container that was incorrectly getting cleaned up.

Image: 123456789012.dkr.ecr.us-west-2.amazonaws.com/vault-data
Container Name: API-vault-vault-data-1

I've anonymized our AWS/ECR ID in the image URL but it's numbers just like that. We've since changed our config to KEEP_CONTAINERS_NAMED = *vault* from **None** and it is correctly keeping the container now. I can do some more testing later today too if needed.

mattdodge avatar Jul 31 '17 18:07 mattdodge

Hi @mattdodge thanks for that info! If you could run some more testing, possibly with DEBUG enabled that would assist us in troubleshooting this issue.

seandtaber avatar Aug 02 '17 18:08 seandtaber

@mattdodge The details you provided basically answer your question: the image name does not match the pattern *:*. images that are started with an implicit latest tag, come back without the tag by the docker inspect --format='{{(index .Config.Image)}}' $CONTAINER_ID command that is used in the script.

Example: saydocker run hello-world starts with container id 1 and docker run hello-world:latest starts with container id 2

docker inspect --format='{{(index .Config.Image)}}' 1 returns hello-world docker inspect --format='{{(index .Config.Image)}}' 2 returns hello-world:latest

Only hello-world:latest will match with the *:* pattern.

The solution:

Use **All** or . to match everything including implicit latest tagged images. (**All** is translated to .: source)

I think the readme should be updated to reflect this behaviour.

CodingContraption avatar Mar 13 '18 13:03 CodingContraption

Won't fix due to retiring project

rasjoh avatar Jun 11 '19 08:06 rasjoh