Hello, I build a docker image but it seems to fail when running it. The url http://localhost:1323/doc/index.html returns a ERR_CONNECTION_REFUSED. Any Idea?
// @title API
// @version 1.0
// @description This is a sample API for testing Swagger
func main() {
router := mux.NewRouter()
router.StrictSlash(true)
router.PathPrefix("/doc").Handler(httpSwagger.WrapHandler)
println(“Running api server at port 1323”)
http.ListenAndServe(":1323", router)
}
And here’s my dockerfile:
FROM golang:alpine AS builder
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/testSwagger/
COPY . .
RUN go get -d -v
RUN go build -o /go/bin/testSwagger
FROM alpine:latest
COPY --from=builder /go/bin/testSwagger /
CMD ["/testSwagger"]
How do you start the container? Exposing only means the port is open for the docker network, if you want it to be reachable from the outside world (which your host is part of) then you also need to publish it using the -p switch.
Then either you expose the port of your container with -p option as previously indicated or you reference the ip of your container instead of localhost. You can find it by docker inspect .