Docker Community Forums

Share and learn in the Docker community.

Connection refused

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
curl: (7) Failed connect to; 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

and u did

docker inspect go-server

to get the assigned address?

you could either (if is the assigned address)

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


if you

docker exec go-server ps 

is your /go/bin/booklist_api process running?

hi @sdetweil thank you for your reply.

Yes, I did docker inspect go-server.



returns connection refused.

I just triggered it now and the results are below:
$ docker exec go-server ps
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.

what makes the booklist_api pgm use port 3000?

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

I used the -p upon docker run.

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

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)

1 Like

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

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…

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

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

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:

Usually it means that the other host has received your connection attempt and is actively refusing your TCP connection, but sometimes an intervening firewall vidmate

Hello, how to require the actual port?

We get this a lot in Apache Hadoop, where it is often caused by configuration errors in the client: which host to talk to, what their DNS or /etc/host tables are set up to, or a mismatch between the ports used by a service and that the clients thinks it should use.

1 Like

Goto Docker -> Settings and tick checkbox Expose daemon on tcp://localhost:2375 without TLS and check