I am very new to docker and i don't know how to take arguments at run time.My code looks like this:
package main import ( "fmt" //"flag" "os" "net/http" "io/ioutil" "reflect" ) func main() { var args string // flag.Parse() // args := flag.Args() fmt.Println("Enter the URL : ") fmt.Scanf("%s ",&args) fmt.Println(args) if len(args) < 1 { fmt.Println(reflect.TypeOf(args),"Please Enter the URL") os.Exit(1) } retrieve(args) //call the retrieve function } func retrieve(url string){ //gives the source code as output. resp, err := http.Get(url) if err != nil{ fmt.Println("read error is:", err) return } body, err := ioutil.ReadAll(resp.Body); if err != nil{ fmt.Println("read error is:", err) return } else{ fmt.Println(string(body)) } }
Dockerfile looks like this:
FROM golang:1.7-alpine ADD . /home WORKDIR /home CMD ["go","run","fetchSource.go"] i have commented the code where it doesn't work.i just want to take arguments at run time so that i uncomment those lines.