Connect() failed (111: Connection refused) while connecting to upstream

I am using Kong and spring boot applications in Docker
Spring boot app configuration:


Here is the Dockerfile

FROM openjdk:12
ADD target/userservice.jar userservice.jar
ENTRYPOINT [“java”,"-jar",“userservice.jar”]

Docker command to push microservice to docker

docker run -p 9090:9090 userservice

APIs added to kong

curl -i -X POST
–url http://localhost:8001/services/
–data ‘name=userservice’
–data ‘url=http://localhost:9090/userservice’

curl -i -X POST
–url http://localhost:8001/services/userservice/routes
–data ‘hosts[]

curl -i -X GET
–url http://localhost:8000/
–header ‘Host:

And the outcome is

*2019/06/12 13:31:13 [error] 39#0: 184849 connect() failed (111: Connection refused) while connecting to upstream, client:, server: kong, request: “GET / HTTP/1.1”, upstream: “”, host: “

Any clues?

Docker should be usually running on host ip and not loopback address (127…0.0.1) so replace “localhost” in your service url in your services config to http://:9090/…

Thanks mgkong for the response.
That has to be done at nginx configuration inside the docker. right?
Can you please give more insight?

In service definition of your Kong server “userservice”, I see the service URL configured is http://localhost:9090/userservice. In this service URL, try replacing “localhost” with actual IP address of the host where this upstream services (hosted on docker) is running.

thanks mgkong. i tried the both public ip and local network ip without any success

when i do docker inspect on my spring boot container below o/p observed

“Gateway”: “”,
“IPAddress”: “”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”

i logged in to KONG container and curl the above ip’s, i see one 302 and another one connection refused

/ # curl -i -H “Accept: application/json” -H “Content-Type: application/json” -X GET

**HTTP/1.1 302 **

Location :

Transfer-Encoding : chunked

Date : Sat, 15 Jun 2019 03:14:07 GMT

and when i do the same on

/ # curl -i -H “Accept: application/json” -H “Content-Type: application/json” -X GET

curl: (7) Failed to connect to port 9090: Connection refused

but i can see from my host machine browser

http://localhost:9090/userservice/ is working fine

any thing i miss here

i think the network ip is different in diff networks here

"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "dbadc3aed953f3b08666c4ae43164a5d33740300f2b58a938ae8f60f1c556402",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "9090/tcp": [
                        "HostIp": "",
                        "HostPort": "9090"
            "SandboxKey": "/var/run/docker/netns/dbadc3aed953",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "kong-net": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                    "NetworkID": "fad502a41154a6422a3270a859eae6c048316fb959ad54d664ad37b49051fa47",
                    "EndpointID": "6b35cf7d1535db925a720013f0b647695e1cde7c2a257b14a12972107c216858",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:04",
                    "DriverOpts": null

i managed to solve the issue. the change worked here is i removed exposure the Spring boot app to the outside world
docker run -p 9090:9090 userservice


   docker run -d --name userservice \
              --net kong-net \