I have a server which is a home network running postgres server on port 5432 on localhost...now I have wrote a app(runs on 3001) which i want to containarized and expose a port on 3001 to receive the incoming request. Then app inside the container will request outside(outgoing traiffic from the container to home network) the for the postgres server on port 5432 which is on home network
My docker-compose file
version: '3.4'
services:
app:
build:
context: .
dockerfile: Dockerfile
image: company
container_name: company
restart: always
command: bash -c "npm run start:dev"
ports:
- 3001:3001 <-- this doesn't take care of the incoming traffic to container
network_mode: 'host' <-- this only resolves the postgres connection from container to home network
volumes:
- ./:/app
although using other stackoverflow solutions, I added the network_mode: 'host' which takes care of the traffic(tcp) from the app inside container to the home network postgres 5432....but the incoming traffic to the container doesn't connect.
My Dockerfile
FROM node:16.13.0 AS builder
WORKDIR /app
COPY ./ ./
EXPOSE 3001
RUN npm install
RUN npm run build
From this solution link I downgraded the docker-compose...but it doesn't solve the incoming traffic to container..
My docker-compose version is 1.27.4 My Docker version is 20.10.8