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 (
_ “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"]


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

(Lutz Horn) #11

See the documentation:

(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

(system) closed #15

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