-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New behavior of r.Run binds to localhost, not 0.0.0.0, issues in Docker #2292
Comments
ref: #2216 |
ping @keob Any thoughts about this? |
Sorry.If you use 0.0.0.0 on windows or mac os it will trigger a firewall block. |
@keob maybe you should pass the |
@DarthHater In the archlinux i can run it. |
user r.Run() |
@keob In my Linux server, I can reproduce this critical issue. package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run()
} Write Dockerfile and build as below: FROM golang:1.14-alpine as build_base
RUN apk add bash ca-certificates git gcc g++ libc-dev
WORKDIR /app
# Force the go compiler to use modules
ENV GO111MODULE=on
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
# This image builds the weavaite server
FROM build_base AS server_builder
# Here we copy the rest of the source code
COPY . .
ENV GOOS=linux
ENV GOARCH=amd64
RUN go build -o /line-login -tags netgo -ldflags '-w -extldflags "-static"' .
### Put the binary onto base image
FROM plugins/base:linux-amd64
LABEL maintainer="Bo-Yi Wu <[email protected]>"
EXPOSE 8080
COPY --from=server_builder /app/templates /templates
COPY --from=server_builder /app/images /images
COPY --from=server_builder /line-login /line-login
CMD ["/line-login"] and run it.
Can't connect to the server. |
@appleboy Can you run it? |
I will bump new version |
@keob Can you post steps? |
DarthHater's demo i can run it,your demo i don't run it |
@keob Please update gin to v1.6.0 version and try it again. |
@appleboy I use 1.6.0 run the DarthHater's demo |
@appleboy I use your demo and gin v1.6.0 and user docker run --network -host can run it,but my pc 8080 port use it.I change port to r.Run(":9090"). |
@keob You can't use the |
@appleboy not use --network host is run |
But i use 9090,docker proxy process running at 8080,so i change to 9090; |
Can you post docker run command and show the output log? |
please wait me,I delete it |
@keob You change the default source code. package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run()
} You can't pass any value in |
cant't run it. But i don't now why DarthHater's demo can run it.🤔🤔 |
Sorry I write a bug |
@keob His example uses gin v1.5 version. |
oh! |
Wow, went to sleep and woke up to a lot of feedback! Thanks y'all! FWIW and I should have likely added this to my report I am using: Docker on OS X (the two people seeing this issue were using High Sierra specifically). We are using Alpine linux as the host OS, and it MIGHT be related to Docker and how it set's up a network (we are using docker-compose to orchestrate). The app itself is mostly a joke, but the behavior caught me off guard, because if others were using gin in Docker, they'd likely sit and scratch their head for a while until they trip across it. My suggestion if the |
Description
Hi! In gin
1.6.0
it appears starting a default gin instance will now bind to:localhost:8080
Instead of previously it would bind to just :8080 (0.0.0.0)
This causes issues when used inside of Docker as it is binding to Docker's localhost rather than 0.0.0.0
How to reproduce
More or less the example above should show gin starting on
localhost:8080
rather than:8080
like in gin 1.5.0Expectations
The expectation is by default, gin should bind the way it previously did
A project that is setup to show this:
https://github.com/DarthHater/hello-world/tree/TestBranch
If you clone that repo, and run
docker-compose up
, you should see the project start on:8080
as it is using gin 1.5.0, if you switch the go.mod to use gin 1.6.0, you'll seelocalhost:8080
, and if you attempt to hit:http://locahost:8080/ping
You'll see empty response, as although Docker has exposed 8080, it's not making it through to the host application since it is bound to Docker's
localhost
rather than the machines0.0.0.0
Let me know if there are any questions! I was teaching some friends how to use gin, etc... and ran into this while doing so.
The text was updated successfully, but these errors were encountered: