Docker (and podman) maintained containers can have annotations, which I can retrieve like this (I removed error handling for brevity):
package main
import (
"context"
"github.com/alecthomas/repr"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)
func main() {
apiClient, err := client.NewClientWithOpts(client.FromEnv)
containers, err := apiClient.ContainerList(context.Background(), container.ListOptions{All: true})
for _, container := range containers {
if container.State == "running" {
repr.Println(container.HostConfig.Annotations) // returns nil for all my nomad jobs
}
}
}
However, I found no way to add annotations to a nomad job. Is that possible somehow?
Or, asked the other way around: when I iterate over all running docker containers using the golang docker client api, how do I know, which one is which?
Thanks in advance,
Tom