Docker container error with Swagger


(Fookiwara) #1

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?

Here’s my main.go file:

package main

import (
“net/http”
_ “testSwagger/docs”
github.com/gorilla/mux
github.com/swaggo/http-swagger
)

// @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"]

EXPOSE 1323


(Lutz Horn) #3

What happens? What output does your running container print to the console or to the log?


(Norbert Melzer) #4

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.


(Fookiwara) #5

i start my container with this:
docker run image_name


(Ivan Matmati) #6

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 .


(Norbert Melzer) #7

As I said, you need to provide -p 1323:1323.


(Fookiwara) #8

what’s the correct synthaxe for this?
docker run image_name -p 1323:1323


(Norbert Melzer) #9

No, it’s betweenrun and the image name.


(Fookiwara) #10

I have this error:
C:\Users\Ahmad-admin>docker run -p 1323:1323 test_swagger:latest
docker: Error response from daemon: driver failed programming external connectivity on endpoint hungry_morse (4942c4a453590820735996d3f11c94aa9c7b216431facf4fc1c707bfc28c4c1b): Error starting userland proxy: mkdir /port/tcp:0.0.0.0:1323:tcp:172.17.0.21:1323: input/output error.


(Lutz Horn) #11

See the documentation: https://docs.docker.com/engine/reference/commandline/run/


(Lutz Horn) #12

OK, so much for Go. Docker support is off topic.


(Norbert Melzer) #13

Seems to be a known issue with docker for windows:


(Fookiwara) #14

Oh yeah, its an known issue. When restarting docker, it works the 2nd time. And everything works now ^^ Thank you very much