From 6c12aee9752a6f879d9d2a4c8905c8b340c81570 Mon Sep 17 00:00:00 2001 From: Fabrizio Steiner Date: Fri, 2 Mar 2018 18:08:57 +0100 Subject: [PATCH] always exclude containers that have the com.centurylinklabs.watchtower.enable set to false. Fixes #169 --- README.md | 12 ++++++++++++ container/filters.go | 20 +++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f84340..74748f8 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,18 @@ docker run -d --label=com.centurylinklabs.watchtower.stop-signal=SIGHUP someimag By default, watchtower will watch all containers. However, sometimes only some containers should be updated. +If you need to exclude some containers, set the *com.centurylinklabs.watchtower.enable* label to `false`. + +```docker +LABEL com.centurylinklabs.watchtower.enable="false" +``` + +Or, it can be specified as part of the `docker run` command line: + +```bash +docker run -d --label=com.centurylinklabs.watchtower.enable=false someimage +``` + If you need to only include only some containers, pass the --label-enable flag on startup and set the *com.centurylinklabs.watchtower.enable* label with a value of true for the containers you want to watch. ```docker diff --git a/container/filters.go b/container/filters.go index 894cbc3..1b3fbbd 100644 --- a/container/filters.go +++ b/container/filters.go @@ -37,10 +37,23 @@ func filterByNames(names []string, baseFilter Filter) Filter { // Filters out containers that don't have the 'enableLabel' func filterByEnableLabel(baseFilter Filter) Filter { return func(c FilterableContainer) bool { - // If label filtering is enabled, containers should only be enabled - // if the label is specifically set to true. + // If label filtering is enabled, containers should only be considered + // if the label is specifically set. + _, ok := c.Enabled() + if !ok { + return false + } + + return baseFilter(c) + } +} + +// Filters out containers that have a 'enableLabel' and is set to disable. +func filterByDisabledLabel(baseFilter Filter) Filter { + return func(c FilterableContainer) bool { enabledLabel, ok := c.Enabled() - if !ok || !enabledLabel { + if ok && !enabledLabel { + // If the label has been set and it demands a disable return false } @@ -57,5 +70,6 @@ func BuildFilter(names []string, enableLabel bool) Filter { // if the label is specifically set. filter = filterByEnableLabel(filter) } + filter = filterByDisabledLabel(filter) return filter }