reddec / mycontainer

Detect self container ID using various methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mycontainer

Go Reference

Detect self container ID using various methods such as: cpuset or mountpoint.

package main

import (
	"fmt"

	"github.com/reddec/mycontainer"
)

func main() {
	containerID, err := mycontainer.ContainerID()
	if err != nil {
		panic(err)
	}

	fmt.Println("Container ID:", containerID)
}

If you have ko installed, you may test it:

$ docker run  $(ko build -L ./example)
....
Container ID: 9b3d8a8c029bb30827f28fa09598693162cb58edb2389eb59e6c5309047643b1

About

Detect self container ID using various methods

License:ISC License


Languages

Language:Go 100.0%