Getting Container IP in a Go application

Viewed 1111

I have a simple Go application running inside a docker container. I wish to get the container IP of that container inside the Go application itself. How can I do that? I am a newbie so please help me out, if this question sounds silly

1 Answers

You can get the hostname using os.hostname() function. Below golang code can give you some idea

package main

import (
    "fmt"
    "os"
)

func main() {
    containerHostname, err := os.Hostname()
}

containerHostname variable will have the hostname of the container.

Related