validate name with isContainerName func

This commit is contained in:
Bas van der Lei 2015-10-02 13:49:27 +02:00
parent 9931854585
commit f8eb8cc982

View File

@ -131,14 +131,20 @@ func ContainerNameToDockerId(name string) string {
return id return id
} }
func isContainerName(name string) bool {
if UseSystemd() {
return dockerCgroupRegexp.MatchString(path.Base(name))
}
return true
}
// Docker handles all containers under /docker // Docker handles all containers under /docker
func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) { func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// docker factory accepts all containers it can handle. // docker factory accepts all containers it can handle.
canAccept := true canAccept := true
// When using Systemd all docker containers have a .scope suffix if !isContainerName(name) {
if UseSystemd() && !strings.HasSuffix(path.Base(name), ".scope") { return false, canAccept, fmt.Errorf("invalid container name")
return false, canAccept, nil
} }
// Check if the container is known to docker and it is active. // Check if the container is known to docker and it is active.