My source code works but when I build a docker image and run it, it skips the line that gets user input, goes to the next line and crashes there. My dockerfile:
FROM golang
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o /usr/local/bin/app ./...
CMD ["app"]
Then I run the command "docker run --env-file ./.env youtubeanalytictool" and it crashes. My code is really long so I'll just post a small snippet of where the problem is:
fmt.Println("Enter channel id: ")
fmt.Scanln(&id)
channel := getChannelInfo(service, id)
When I run the image, I get the error:
Enter channel id:
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
main.getChannelInfo(0x9a4bc0?, {0x0, 0x0})
/usr/src/app/retrieve_data.go:47 +0x3f9
main.main()
/usr/src/app/main.go:34 +0x25c
It skips the line where it scans for user input and goes straight to the next line. This doesn't happen when I run my source code. Am I missing something in my dockerfile that allows user input?