Docker中连续的空控制台输入

时间:2017-08-16 09:31:28

标签: docker go

我正在尝试在Docker中运行Go控制台程序。一切正常,除了我拿控制台输入的部分。不起作用的部分是:

func ListenTerminalInput() {
    reader := bufio.NewReader(os.Stdin)
    in := ""
    for in != "exit" {
        in, _ = reader.ReadString('\n')
        in = strings.Replace(in, "\n", "", -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.")
        }
    }
}

此代码将默认语句写入控制台,与循环执行一样快。它只在Docker容器中执行时执行此操作,如果我在容器外执行它,它可以正常工作。

这是我的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

这是我的docker-compose.yml

   version: '3'
   services:

     server:
       image: goserver
       ports:
        - "56566:56566"
        - "56567:56567"
       volumes:
         - ./shared:/shared

以下是我在Docker中运行时获得的输出

Docker execution console output

这是我在Docker

之外运行时获得的输出

Normal execution console output

0 个答案:

没有答案