Ignore systemd 'containers' in the docker driver

This commit is contained in:
Bas van der Lei 2015-07-18 21:46:34 +02:00
parent e675b00a40
commit 7788c8bd27

View File

@ -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)