List all Docker containers without a specific label
List and find containers without a specific label
Labels are an easy way to opt containers in or out of automation like deunhealth, but it is just as easy to forget to add one when you create a new service.
docker ps -aq | grep -v -E $(docker ps -aq --filter='label=deunhealth.restart.on.unhealthy' | paste -sd "|" -) | while read line ; do docker ps --filter "id=$line" --format "{{.Names}}"; doneAll containers without label "deunhealth.restart.on.unhealthy"
docker ps -aq | grep -v -E $(docker ps -aq --filter='label=deunhealth.restart.on.unhealthy' | paste -sd "|" -) | while read line ; do name=$(docker ps --filter "id=$line" --format "{{.Names}}") && if [[ $name != "deunhealth" ]]; then echo "$name"; fi; doneAll containers without label "deunhealth.restart.on.unhealthy" except the one named "deunhealth"
The second version of the command filters out the automation container itself, so you only see the containers that actually still need the label.
Looking for help?
If you are looking for some help or want a quick chat, please head over to the Discord Community!