From 7788c8bd27d7e18d23ef2234e7b408e9836b7e6e Mon Sep 17 00:00:00 2001 From: Bas van der Lei Date: Sat, 18 Jul 2015 21:46:34 +0200 Subject: [PATCH] Ignore systemd 'containers' in the docker driver --- container/docker/factory.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/container/docker/factory.go b/container/docker/factory.go index e449586e..ad7541af 100644 --- a/container/docker/factory.go +++ b/container/docker/factory.go @@ -42,6 +42,10 @@ var DockerNamespace = "docker" var dockerRootDir = flag.String("docker_root", "/var/lib/docker", "Absolute path to the Docker state root directory (default: /var/lib/docker)") var dockerRunDir = flag.String("docker_run", "/var/run/docker", "Absolute path to the Docker run directory (default: /var/run/docker)") +// Regexp that identifies docker cgroups, containers started with +// --cgroup-parent have another prefix than 'docker' +var dockerCgroupRegexp = regexp.MustCompile(`[A-z]+-([a-z0-9]+)\.scope`) + // TODO(vmarmol): Export run dir too for newer Dockers. // Directory holding Docker container state information. func DockerStateDir() string { @@ -119,8 +123,9 @@ func ContainerNameToDockerId(name string) string { // Turn systemd cgroup name into Docker ID. if UseSystemd() { - id = strings.TrimPrefix(id, "docker-") - id = strings.TrimSuffix(id, ".scope") + if matches := dockerCgroupRegexp.FindStringSubmatch(id); matches != nil { + id = matches[1] + } } return id @@ -140,6 +145,12 @@ func FullContainerName(dockerId string) string { func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) { // docker factory accepts all containers it can handle. canAccept := true + + // When using Systemd all docker containers have a .scope suffix + if UseSystemd() && !strings.HasSuffix(path.Base(name), ".scope") { + return false, canAccept, nil + } + // Check if the container is known to docker and it is active. id := ContainerNameToDockerId(name)