I'm trying to run a Go console program in Docker. Everything works fine except the part where I take console input. The part that doesn't work is this:
func ListenTerminalInput() {
reader := bufio.NewReader(os.Stdin)
in := ""
for in != "exit" {
in, _ = reader.ReadString('
')
in = strings.Replace(in, "
", "", -1)
in = strings.ToLower(in)
switch in {
case "exit":
continue
case "status":
PrintStatus()
continue
case "servers":
PrintServers()
continue
case "clients":
PrintClients()
continue
case "help":
PrintHelp()
continue
default:
fmt.Println("Please make a valid choice. Type \"help\" for help.")
}
}
}
This code writes default statement to the console as fast as for loop executes. It only does this when it is execute in Docker container, if I execute it outside the container it works fine.
Here is my Dockerfile
FROM golang:1.9
MAINTAINER Hüseyin Atakan Çiçek
EXPOSE 56566
EXPOSE 56567
VOLUME /shared
WORKDIR /shared
CMD ["go", "run", "server.go"]m
Here is my docker-compose.yml
version: '3'
services:
server:
image: goserver
ports:
- "56566:56566"
- "56567:56567"
volumes:
- ./shared:/shared
Here is the output I get when I run it in Docker
Docker execution console output
Here is the output I get when I run it outside Docker