Reputation: 337
main.go
package main
import (
"bufio"
"os"
"time"
)
func main() {
code, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
panic(err)
}
time.Sleep(time.Second * 10)
}
Dockerfile
FROM golang:1.17
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
CMD ["go","run","main.go"]
When create docker container and run it get and error like it:
I want to get user input from terminal when run docker container
Upvotes: 2
Views: 580
Reputation: 648
By using ENTRYPOINT
instead of CMD
your user could pass parameters after the docker run
command:
ENTRYPOINT ["echo", "Hello World"]
docker run <container-name>
> Hello World
docker run <container-name> test
> Hello World test
However you should use os.Args
to retrieve those argument.
Upvotes: 1