dou760663 2017-07-09 11:58 采纳率: 100%
浏览 161

无法从Docker访问Golang Web服务器

I am using the Gorilla framework in Go to expose a webservice. I have a "Hello World" endpoint at /hello which works fine when hit from Postman, browser or curl.

The problem arises when I bundle it with Docker. My Dockerfile is as below

FROM alpine
COPY ./target/himer-users-go /app
ENV PORT 9000
RUN echo $PORT
ENTRYPOINT /app
EXPOSE ${PORT}

Now I can ssh into the container and ping the server using wget (since alpine doesn't come bundled with curl)

But when I run the image like

docker run -d -p 9000:9000 namespace/image

I can't access the server in any way from my host system.

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douchuituo3032 2017-07-09 12:09
    关注

    I solved it by exposing the server at 0.0.0.0 instead of localhost

    The problem is that I've told my webserver to only serve requests sent to localhost. Because of the network mangling that Docker does, none of the traffic showing up to your webserver look to the webserver as though they were sent to localhost. By telling the webserver to listen on 0.0.0.0, I'm effectively telling it that it doesn't care where the traffic was originally sent and it will accept it all.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码