0

We have two apps running in the system, one is from docker and another is directly running on the system, We need to access the system's app inside container app using localhost:8082 API

We are running a node JS container which is port 5000 on Windows 10 Home using Docker toolbox, and running an app outside container means directly from the machine which is 8042, We need to access this localhost:8042 API inside the node container, how can We archive it?, using Docker version 19.03.1

Run cmd:

docker container run -p --net=host -it -v `pwd`:/usr/src/app --rm --name server server/windows:v1

Error: Connection refuesed 127.0.0.1:8042 while running docker container.

Complete Error:

(node:80) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:8042
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
(node:80) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,
use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:80) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.

Dockerfile

FROM node:12

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install
COPY . .

# Specify port app runs on
EXPOSE 5000

# Run the app
CMD [ "npm", "run", "dev"]
151291
  • 3,308
  • 7
  • 48
  • 81
  • 1
    You need to find some IP address of the host system that can be reached; `localhost` in Docker is generally "this container". This is trickier in Docker Toolbox (because it runs inside a VM) but the linked question has [an answer suggesting there is a fixed IP address that will work](https://stackoverflow.com/a/53234046/10008173). – David Maze Mar 30 '20 at 11:30
  • @DavidMaze, It works fine, but I need a common solution not Only for Docker toolbox. because it will be difficult to use it for multiple platforms. I can not use the same static IP for all the platforms right? – 151291 Mar 31 '20 at 05:03

1 Answers1

-1

Error: Connection refuesed 127.0.0.1:8042 while running docker container.

This is because port 8042 is being used on the host machine so you cannot map that port while running the container.

Instead, you should try --net=host while running the container.

docker container run --net=host -it -v `pwd`:/usr/src/app --rm --name server server/windows:v1

Read this for more detail on docker's --net=host property.

Kapil Khandelwal
  • 1,096
  • 12
  • 19