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
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
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…
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
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.