来自Docker容器的ERR_EMPTY_RESPONSE [英] ERR_EMPTY_RESPONSE from docker container

查看:495
本文介绍了来自Docker容器的ERR_EMPTY_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个小时里,我一直在试图解决这个问题,但是我被困住了.

我有一个非常简单的Dockerfile,如下所示:

  FROM高山:3.6COPY gempbotgo/COPY配置/configsCMD ["/gempbotgo"]展览8025 

gempbotgo只是运行Web服务器和其他一些东西的go二进制文件.该网络服务器运行在8025上,应该可以打个招呼.

我的问题是暴露端口.我这样运行容器(构建后)

  docker run --rm -it -p 8025:8025 asd 

一切似乎都很好,但是当我尝试在浏览器中打开127.0.0.1:8025或尝试使用wget时,我只会得到一个空响应.Chrome:ERR_EMPTY_RESPONSE

该端口已使用,但不受Windows 10系统上防火墙的限制.仅在我的"Windows上的Ubuntu上的Bash"终端上运行不带容器的go二进制文件,然后浏览至127.0.0.1:8025即可顺利进行.其他地址返回的是"ERR_CONNECTION_REFUSED",例如127.0.0.1:8030,因此该端口上肯定有活动的东西.

然后我和

一起进入化妆器

  docker exec -it e1cc6daae4cf/bin/sh 

并使用wget进行检查.也没有问题.使用"Hello World"下载了index.html文件

任何想法为何Docker不发送任何数据?我也用docker-compose运行了我的容器,但是在那里没有区别.

我还在外部托管的VPS上运行了该容器.那里同样的问题...(Debian)

我的代码:(请注意Makefile) https://github.com/gempir/gempbotgo/tree/docker

在收到一些评论后,我将Dockerfile更改为多阶段构建.现在这是我的Dockerfile:

  FROM golang:latestWORKDIR/go/src/github.com/gempir/gempbotgo运行去获取github.com/gempir/go-twitch-irc \&&去github.com/stretchr/testify/assert \&&去github.com/labstack/echo \&&去获取github.com/op/go-logging复制 ..RUN CGO_ENABLED = 0 GOOS = linux转到build -a -installsuffix cgo -o app.来自高山:最新运行apk --no-cache添加ca证书WORKDIR/root/COPY配置./configs复制--from = 0/go/src/github.com/gempir/gempbotgo/app.CMD ["./app"]展览8025 

遗憾的是,这并没有改变任何内容,我将所有内容尽可能地保留在此处的指南中:解决方案

您的问题是您绑定到代码内的 127.0.0.1:8025 .这样可以使代码从容器内部工作,而不是从外部工作.

您需要绑定到 0.0.0.0:8025 才能绑定到容器内的所有接口.因此,您的Go应用也可以接受来自容器外部的流量

I've been trying to figure this out in the last hours but I'm stuck.

I have a very simple Dockerfile which looks like this:

FROM alpine:3.6
COPY gempbotgo /
COPY configs /configs
CMD ["/gempbotgo"]
EXPOSE 8025

gempbotgo is just an go binary which runs a webserver and some other stuff. The webserver is running on 8025 and should answer with an hello world.

My issue is with exposing ports. I ran my container like this (after building it)

docker run --rm -it -p 8025:8025 asd

Everything seems fine but when I try to open 127.0.0.1:8025 in the browser or try a wget i just get an empty response. Chrome: ERR_EMPTY_RESPONSE

The port is used and not restricted by the firewall on my Windows 10 system. Running the go binary without container just on my "Bash on Ubuntu on Windows" terminal and then browsing to 127.0.0.1:8025 works without a hitch. Other addresses returned a "ERR_CONNECTION_REFUSED" like 127.0.0.1:8030 so there definetly is something active on the port.

I then went into the conatiner with

docker exec -it e1cc6daae4cf /bin/sh

and checked in there with a wget what happens. Also there no issues. index.html file gets downloaded with a "Hello World"

Any ideas why docker is not sending any data? I've also ran my container with docker-compose but no difference there.

I also ran the container on my VPS hosted externally. Same issue there... (Debian)

My code: (note the Makefile) https://github.com/gempir/gempbotgo/tree/docker

Edit:

After getting some comments I changed my Dockerfile to a multi-stage build. This is my Dockerfile now:

FROM golang:latest
WORKDIR /go/src/github.com/gempir/gempbotgo
RUN go get github.com/gempir/go-twitch-irc \
    && go get github.com/stretchr/testify/assert \
    && go get github.com/labstack/echo \
    && go get github.com/op/go-logging
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY configs ./configs
COPY --from=0 /go/src/github.com/gempir/gempbotgo/app .
CMD ["./app"]  
EXPOSE 8025

Sadly this did not change anything, I kept everything as close as possbile to the guide here: https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds

I have also tried the minimalist Dockerfile from golang.org which looks like this:

FROM golang:onbuild
EXPOSE 8025

But no success either with that.

解决方案

Your issue is that you are binding to the 127.0.0.1:8025 inside your code. This makes the code work from inside the container but not outside.

You need to bind to 0.0.0.0:8025 to bind to all interfaces inside the container. So traffic coming from outside of the container is also accepted by your Go app

这篇关于来自Docker容器的ERR_EMPTY_RESPONSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆