Revel和Docker容器

I am attempting to create a docker container that contains the revel skeleton app. Everything seems to build OK and the container is created but when I go to localhost:9000 in my browser nothing comes up.
To make sure my environment is working properly I created a simple hello world go app and created a docker container for it. It worked OK using the same port 9000. This makes me think that there is something not configured properly in my dockerfile.

Dockerfile:

#Compile stage
FROM golang:1.11.4-alpine3.8 AS build-env
ENV CGO_ENABLED 0
RUN apk add --no-cache git
ADD . /go/src/revelapp

# Install revel framework
RUN go get -u github.com/revel/revel
RUN go get -u github.com/revel/cmd/revel
#build revel app
RUN revel build revelapp app dev

# Final stage
FROM alpine:3.8
EXPOSE 9000
WORKDIR /
COPY --from=build-env /go/app /
ENTRYPOINT /run.sh

Docker command used:

docker build -t revelapp . && docker run -p 9000:9000 --name revelapp revelapp 

After command is executed and container is created the console shows:

INFO  17:25:01    app     run.go:32: Running revel server                      
INFO  17:25:01    app   plugin.go:9: Go to /@tests to run the tests.           
Revel engine is listening on.. localhost:9000

When I go to localhost:9000 I would expect to see the text It Works!

duanpai9945
duanpai9945 它与控制台中显示的内容相同,即上面我的帖子的最后一部分。
一年多之前 回复
duanchu9914
duanchu9914 那么,容器日志中有什么?
一年多之前 回复
douchongbang6011
douchongbang6011 当我转到localhost:9000chrome时显示:localhost没有发送任何数据。ERR_EMPTY_RESPONSE
一年多之前 回复
duanjuelu8874
duanjuelu8874 当您尝试访问URL时会发生什么?
一年多之前 回复

1个回答



您正在监听 localhost:9000 </ code>,因此127.0.0.1指向您的容器,而不是您的本地 </ p>

您有两种解决方案可以使其正常工作:</ p>


  • 0.0.0.0:9000 </ 代码> </ li>
  • 在docker运行命令中使用--network =“ host”:Docker容器中的127.0.0.1将指向您的docker主机。</ li>
    </ ul> \ n </ div>

展开原文

原文

You're listening on localhost:9000, so 127.0.0.1 points to your container and not your local machine.

You have two solutions to make it work:

  • Listen on 0.0.0.0:9000
  • Use --network="host" in your docker run command: 127.0.0.1 in your docker container will point to your docker host.

dtsi9484
dtsi9484 通过在Revel app.conf文件中将http.addr设置为0.0.0.0,可以使它正常工作。
一年多之前 回复
douzhi9395
douzhi9395 我正在使用Windows docker CE,因此网络接口已绑定到本地计算机。 如我之前所说,我使用一个简单的hello world go应用程序和相同的dockerfile进行了测试。 使用localhost:9000一切正常
一年多之前 回复
douhuantui6259
douhuantui6259 我敢肯定8000是错字。 指向的是0.0.0.0,而不是localhost,而不是端口。
一年多之前 回复
dsaf415212
dsaf415212 您在哪里看到端口8000? 我在任何地方的问题中都找不到。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问