As stated by Ponsakorn30214, the requests are failing because (obviously) url=http://127.0.0.1:4002
means "localhost" from the point of view of Kong docker container.
Alternative Solution
Another possibility to solve the issue would be to use the private IP address of the machine both containers are running on, but that'll break in case the IP address gets reassigned.
Patch
Patch the Kong service with the following command (suppose the host IP address is 192.168.XXX.XXX
):
curl --request PATCH --url localhost:8001/services/test_service --data url=http://192.168.XXX.XXX:4002
Result
Test HTTP request to the gateway:
$ curl -X GET http://localhost:8000/test/testFoo$ curl -X GET http://localhost:8000/test/fooFoo$ curl -X GET http://localhost:8000/test/barBar