咕噜代码: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" ]然后运行它:$ docker run --rm -p 8080:8080 serverserver starting...它适用于容器(安装curl后):$ docker exec 3c3 -it curl localhost:8080hit 3c398d80ca79但它在主机中不起作用:$ curl localhost:8080curl: (52) Empty reply from server$ nc localhost 8080 $ # nc exit immediatly如果我运行而不是:nc -l -p 8080./server$ docker run --rm -it -p 8080:8080 alpine:latest nc -l -p 8080并在主机中运行它:$ curl localhost:8080然后我可以在容器中得到请求,并且everthing工作得很好。那么,在高山图像中卷曲golang服务器时有什么问题呢?
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消