Docker publishing not working correctly for golang application

I am trying to run the golang web server application (which is trying to run the go blog, which runs the same tools as the golang power blog ) through the docker. It works fine without dockers, but does not give an answer if I use docker. I don’t know why this is happening, as for a much simpler go web application , the same approach on docker works fine. Below is a description of the various commands that I used. Any help would be greatly appreciated.

docker pull maddyonline/gotutorial
docker run -d --publish 8080:8080 --name gotut maddyonline/gotutorial

81bc36e385286326a6d9f74322515a7b9748e493275c3426bcc6848a4589a7e7

docker ps

IMAGE TEAM CONTAINER
CREATED NAME PORT CONDITIONS 81bc36e38528 maddyonline / tutorial "go-wrapper run" 20 seconds ago Up 20 seconds 0.0.0.0:8080-> 8080 / tcp gotut

curl localhost:8080

curl: (52) An empty response from the server

docker exec gotut curl localhost:8080
<!DOCTYPE html>
<html>
<head>

And the rest of the file

The docker file I use is very simple.

FROM golang:onbuild
EXPOSE 8080

I experimented with the same docker file with a much simpler golang application on the same server. And it works.

docker pull maddyonline/gowebapp
docker run -d --publish 8080:8080 --name gowebapp maddyonline/gowebapp
curl localhost:8080/icecream

Hi, I think I like ice cream!

+4
source share
1 answer

I found two problems with your current code.

-, localhost main.go 0.0.0.0. , , - , localhost. - , Docker, , -, -, localhost. -, 0.0.0.0, , , , .

var (
    httpFlag   = flag.String("http", "0.0.0.0:8080", "HTTP listen address") // <--- Here it the change. It roughly line 25 of [main.go](https://github.com/maddyonline/gotutorial/blob/master/main.go#L25)
    originFlag = flag.String("origin", "", "web socket origin for Go Playground (e.g. localhost)")
    baseFlag   = flag.String("base", "", "base path for articles and resources")
)

, onbuild Dockerfile, . , , , , - go-wrapper, Docker onbuild. , , Go . .

Go, , , onbuild Dockerfile , . , onbuild Dockerfile, , Docker.;) , , :

FROM golang:1.4.2

RUN mkdir -p /go/src/github.com/maddyonline/gotutorial
WORKDIR      /go/src/github.com/maddyonline/gotutorial

ADD . /go/src/github.com/maddyonline/gotutorial
RUN go-wrapper download
RUN go-wrapper install

EXPOSE 8080
CMD ["go-wrapper", "run"]

, , . , , , . Go.

, , , , . , - .

+1

All Articles