1

I'm trying to introduce docker for local development into an existing project.

I have two services A (previously being run on localhost:5000) & B (previously being run on localhost:5001). A is a login application whereas B is the main application. A takes the username/password from the user, validates credentials & if valid, redirects the user to appropriate service B's entry point i.e. localhost:5001/<user_role> from where application B takes over.

When running without docker, this redirection between services works fine. But when using docker and running the projects, this redirection breaks (except when I use host network driver). I can access service A, login successfully but when the redirection happens, the browser's address bar shows the redirected entry point of service B and the browser says "The site can't be reached" and the request fails.

Here are my docker files:

Service A

Run as: docker run -p 5000:5000 --name service_a_1 service_a

FROM node:10

WORKDIR /home/node/serviceA
COPY ./package*.json ./
RUN npm install

COPY . .

CMD ["npm", "start"]

EXPOSE 5000

Service B

Run as: docker run -p 5001:5001 --name service_b_1 service_b

FROM node:10

WORKDIR /home/node/serviceB
COPY ./package*.json ./
RUN npm install

COPY . .

CMD ["npm", "start"]

EXPOSE 5001

But when I use --network=host when running these containers, the redirection works fine but it fails with a bridge network driver. I have done my research going through the docker's documentation on networking and some tutorials on docker networking.

Questions:

  1. Can the behavior that I want be achieved using bridge network?
  2. Why is it not working for bridge network driver but works on host?
Kiran
  • 340
  • 2
  • 11
  • What is the contents of your `docker-compose` file? I use networking in my docker-compose file and all containers in the same `bridge` network can ping each other. – Saeed Mar 06 '21 at 03:16
  • @Saeed I"m trying to do this without `docker-compose` first. But anyway, docker itself attaches the containers to `bridge` network by default. I don't think we need `docker-compose` for that. If I go into `serviceA` and ping `serviceB` with B's IP address, the ping does go through. – Kiran Mar 08 '21 at 05:53
  • @Saeed, Thanks for your interest. I've found the solution to my problem & I've answered my own question. – Kiran Mar 08 '21 at 07:22

1 Answers1

0

Found Cannot run webpack-dev-server inside docker after some additional research. This solved my issue.

Additional resources:

Kiran
  • 340
  • 2
  • 11