ERR_EMPTY_RESPONSE from docker container

匆匆过客 提交于 2020-12-30 05:05:07

问题


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.


回答1:


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




回答2:


Another possibility why you are getting that error is that the docker run command is run through a normal cmd prompt and not the admin command prompt. Make sure you run as an admin!




回答3:


Adding to the accepted answer: I had the same error message trying to run docker/getting-started.

The problem was that "getting-started" is using port 80 and this was "occupied" (netsh http show urlacl) on my machine.

I had to use docker run -d -p 8888:80 docker/getting-started where 8888 was an unused port. And then open "http://localhost:8888/tutorial/".



来源:https://stackoverflow.com/questions/46184173/err-empty-response-from-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!