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:
- Can the behavior that I want be achieved using
bridge
network? - Why is it not working for
bridge
network driver but works onhost
?