Docker container does not see 127.0.0.1 address
I have Golang code:
serverAddress := os.Getenv("SERVER_ADDRESS")
server := &http.Server{
Addr: serverAddress,
Handler: router,
}
if internalErr := server.ListenAndServe(); internalErr != nil {
logger.Fatal("failed to start server", zap.Error(internalErr))
}
And I have Dockerfile:
FROM golang:1.22 AS build-stage
WORKDIR /app
COPY ./ ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /match-bot cmd/match_bot/main.go
FROM gcr.io/distroless/base-debian11 AS build-release-stage
COPY --from=build-stage /match-bot /match-bot
ENV SERVER_ADDRESS = "127.0.0.1:8080"
EXPOSE 8080
ENTRYPOINT ["/match-bot"]
After it I tried to do that:
docker build -t test .
docker run -d --restart on-failure -p 8080:8080 --network=bridge test
But it does not work – I have the following error:
{"level":"fatal","ts":1719151000.4234245,"caller":"match_bot/main.go:99","msg":"failed to start server","error":"listen tcp: lookup = 127.0.0.1: no such host","stacktrace":"main.main.func1nt/app/cmd/match_bot/main.go:99"}
I have already tried localhost:8080
, 0.0.0.0:8080
, 127.0.0.1:8080
, :8080