Docker container error with Swagger

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 (
_ “testSwagger/docs”

// @title API
// @version 1.0
// @description This is a sample API for testing Swagger
func main() {
router := mux.NewRouter()
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"]


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

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.

1 Like

i start my container with this:
docker run image_name

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 .

1 Like

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

1 Like

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

No, it’s betweenrun and the image name.

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: input/output error.

See the documentation:

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

1 Like

Seems to be a known issue with docker for windows:

1 Like

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.