diff --git a/.gitignore b/.gitignore index d76f98b2..76388b3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ docker-gen dist *.gz +.idea diff --git a/context.go b/context.go index 80a6bd7d..5a8439c3 100644 --- a/context.go +++ b/context.go @@ -177,6 +177,8 @@ func GetCurrentContainerID() string { return id } else if id := matchECSCurrentContainerID(strLines); id != "" { return id + }else if id := matchDockerLimitCurrentContainerID(strLines); id != "" { + return id } } } @@ -210,3 +212,17 @@ func matchECSCurrentContainerID(lines string) string { return "" } + +func matchDockerLimitCurrentContainerID(lines string) string { + regex := "/docker[_-]limit.slice[/-]([[:alnum:]]{64})(\\.scope)?$" + re := regexp.MustCompilePOSIX(regex) + + if re.MatchString(string(lines)) { + submatches := re.FindStringSubmatch(string(lines)) + containerID := submatches[1] + + return containerID + } + + return "" +} \ No newline at end of file