1

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.

1
  • Please paste your code to your question. Commented May 24, 2017 at 6:54

2 Answers 2

1

Specify the full command with all args like :

docker run myimage:latest go run fetchSource.go arg1 arg2 arg3 

Edit :

When you specify something at the end of you docker run command, you're overwriting the "Entrypoint" or "Cmd" section of you Dockerfile. You have to specify the full command.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks,it worked but can you specify why docker run -it myapp http://www.comshows: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"go run\": executable file not found in $PATH".
1

I have tried with the following changes in Dockerfile and it also worked.

FROM golang:1.7-alpine ADD . /home WORKDIR /home # This builds a binary first RUN ["go", "build"] # Now you can run the executable and pass arguments at the run time. ENTRYPOINT ["./home"] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.