Docker Community Forums

Share and learn in the Docker community.

Connection refused


(Sukidesuaoi) #1

Hi all,

I have been trying out put go api in docker. but apparently when i do curl, I always get connection refused.
could anybody help me?

I already tried using both localhost and the ip assigned when i do docker inspect .

Below is how I run the api.
docker run --rm --net compose_default -p 3000:3000 --name go-server -d gobuild

Response from curl:
$ curl -i -X GET http://172.19.0.6:3000/all/
curl: (7) Failed connect to 172.19.0.6:3000; Connection refused

Dockerfile is as follows:
FROM golang
ADD booklist_api /go/src/workspace/booklist/booklist_api
RUN go install workspace/booklist/booklist_api
ENTRYPOINT /go/bin/booklist_api
EXPOSE 3000


(Sam) #2

and u did

docker inspect go-server

to get the assigned address?

you could either (if 172.19.0.6 is the assigned address)

http://172.19.0.6:3000/all/

or (as you mapped the container port to a host port)

http://localhost:3000/all/

if you

docker exec go-server ps 

is your /go/bin/booklist_api process running?


(Sukidesuaoi) #3

hi @sdetweil thank you for your reply.

Yes, I did docker inspect go-server.

http://172.19.0.6:3000/all/

and

http://localhost:3000/all/

returns connection refused.

I just triggered it now and the results are below:
$ docker exec go-server ps
PID TTY TIME CMD
1 ? 00:00:00 sh
5 ? 00:00:00 booklist_api
8 ? 00:00:00 ps

I don’t know what I’m missing in my setup.


(Sam) #4

what makes the booklist_api pgm use port 3000?

expose doesn’t know if the app Actually uses port 3000 or not


(Sukidesuaoi) #5

I used the -p upon docker run.

docker run --rm --net compose_default -p 3000:3000 --name go-server -d gobuild


(Sam) #6

no… that is how DOCKER maps ports… but the booklist_api application actually has to USE the port…

how do you configure IT to listen on port 3000? (forget about docker on this question)


(Sukidesuaoi) #7

ohhh I see your point. I initially thought that the exposed port usually becomes the port for the server. Thank you! :slight_smile:


(Sam) #8

server is a vague term…

it will be the port for the application on the machine which is running an application or data server which listens on that port.

all docker is doing is documenting that some application INTENDS to use that port (if anyone outside cares to know)… your application can USE the port, and NOT have an expose statement, and you could still use -p.

expose is good for allowing docker to auto map (-P) or other inspecting apps (like docker-compose) to attempt to auto link using and consuming applications… but it still just documentation…


(Sukidesuaoi) #9

@sdetweil Thank you so much for this! :slight_smile: it now works


(Sam) #10

what did you do to fix this (for others that might follow)


(Sukidesuaoi) #11

The actual port the application uses isn’t the 3000, even though I have ported and exposed port 3000 upon running it in docker.

The actual port was the one used inside the code. :slight_smile: