validate name with isContainerName func
This commit is contained in:
parent
9931854585
commit
f8eb8cc982
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user