咕嚕代碼:fmt.Println("server starting...")http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { name, _ := os.Hostname() resp := fmt.Sprintf("hit %s", name) w.Write([]byte(resp))})http.ListenAndServe("127.0.0.1:8080", nil)Dockerfile:FROM alpine:latestCOPY ./server .CMD [ "./server" ]然后運(yùn)行它:$ docker run --rm -p 8080:8080 serverserver starting...它適用于容器(安裝curl后):$ docker exec 3c3 -it curl localhost:8080hit 3c398d80ca79但它在主機(jī)中不起作用:$ curl localhost:8080curl: (52) Empty reply from server$ nc localhost 8080 $ # nc exit immediatly如果我運(yùn)行而不是:nc -l -p 8080./server$ docker run --rm -it -p 8080:8080 alpine:latest nc -l -p 8080并在主機(jī)中運(yùn)行它:$ curl localhost:8080然后我可以在容器中得到請求,并且everthing工作得很好。那么,在高山圖像中卷曲golang服務(wù)器時(shí)有什么問題呢?
- 2 回答
- 0 關(guān)注
- 130 瀏覽
添加回答
舉報(bào)
0/150
提交
取消