Newman/Docker - connect ECONNREFUSED

Hey all.

I am running into a bit of a road block on some newman tests in a docker container I am running. When I run my tests against a service thats in one of my test envs, it runs fine.
As soon as I run it locally, it fails with the error:

The only difference I can find here is the explicit port number I am using when running locally.

This only seems to be an issue when its going though the newman docker image. If I remove that from the equation and just use my local newman instance then it works fine.

I am guessing there is something I need to pass in to address this port 7000 issue. Just not able to find a clear answer.

Here is an example of what I am doing:

docker pull postman/newman_ubuntu1404:latest
docker run
-v $PWD/service-test/:/etc/newman postman/newman_ubuntu1404:latest
run “src/test/resources/collection.json”
–environment “test_configs/test.json”
–delay-request 100

Any thoughts would be greatly appreciated.


Hi @tmccann,

A docker container by default has a separate network bridge from the host. So when you try to access port 6000 on the localhost from inside the container you get ECONNREFUSED as no application is listening on that port inside the container. There are two ways you can get around this.

  1. Use the host networking in the container - simply pass --network host to the docker run command.

  2. Call the host with its IP address. This is not as straight forward as using the host network stack. You can follow the steps in this blog post to get the host IP inside your container.

1 Like

Hi @akshaybist
So I tried what you suggested above but still getting the ECON error.

I have added in the --network host parameter but still does not seem to like it.

docker pull postman/newman_ubuntu1404:latest
docker run --network host -v $PWD/service-test/:/etc/newman postman/newman_ubuntu1404:latest run "src/test/resources/collection.json" --environment "test.json" --disable-unicode --color --delay-request 100

Actually, I think I may have figured out why its not working for me locally.

The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.

Hey @tmccann, you’re correct on the part that specifying a net host doesn’t work as expected in Docker for mac. As an alternative maybe you can go ahead with the second approach as mentioned by @akshaybist and specify the IP address of your host machine.

@debjeetsarkar Definitely need to play around with that a bit and see if I can get it to work as I like.
Where this is with a CI pipeline it could cause some issues but I am sure I can figure it out.
Thx :slight_smile:

So it seems I am not having a ton of luck with this. My issue could be unique but I may also being doing something wrong.

I have a service running locally on my Mac, on port 7000.
When I run my tests:

docker run -p 7000:80 -v /service-test/:/etc/newman postman/newman_ubuntu1404:latest run collection.json --environment test.json --disable-unicode --color --delay-request 100`

I get the following error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint agitated_colden (a7d2ca6efdff3be8bc42f4bde3d04cfb03eb06c21493c04126e2827cd5551844): Error starting userland proxy: Bind for failed: port is already allocated.
ERRO[0000] error waiting for container: context canceled

This makes sense that it cant bind on that port because my local service is using it.
Does this make sense to anyone else?