Description
The recent update to aws ecs agent 1.16.0 changed the default prefix for the control groups inside a docker container so that the regex inside GetCurrentContainerID() (https://github.com/jwilder/docker-gen/blob/master/context.go#L161) no longer works. I submitted an issue and PR to aws here aws/amazon-ecs-agent#1119 but they have given reasons for why they won't accept it.
They also linked out to some other issues for docker introspection which is still an open issue for a standard way to get this information. The latest ecs agent also has some ability to get container meta data.
All of this leads me with knowing the problem but not a great idea for a solution.
We could easily just add a secondary check to the regex to work for both standard docker or ecs but I'm not a big fan of making a platform specific change.
var dockerRegex = "/docker[/-]([[:alnum:]]{64})(\\.scope)?$"
var ecsRegex = "/ecs/[^/]{1,}/([[:alnum:]]{64})(\\.scope)?$"
var dockerRe = regexp.MustCompilePOSIX(dockerRegex)
var ecsRe = regexp.MustCompilePOSIX(ecsRegex)
if dockerRe.MatchString(line) {
var submatches = dockerRe.FindStringSubmatch(line)
var containerID = submatches[1]
fmt.Printf("Docker %s", containerID)
} else if ecsRe.MatchString(line) {
var submatches = ecsRe.FindStringSubmatch(line)
var containerID = submatches[1]
fmt.Printf("ECS %s", containerID)
} else {
fmt.Print("We didn't get anything")
}
I wanted to reach out and at least get some other people thinking about the issue and see if there are any other ideas.