I am developing an application which runs on docker containers. I have two node js applications where one is running on port number 5000 and another on 8888 in the docker. I would like to send http request to the node app's route which runs on port 8888 from node app 5000. but it is not working. but when I tried to access the same api end point of port 8888 application it is working fine on browser as well as a none dockerize node js app. can anyone help me to resolve the issue? below is my docker-compose.yml file
version: "3.8"
services:
node-sdc-service:
build:
context: .
dockerfile: Dockerfile-dev
environment:
CHOKIDAR_USEPOLLING: 'true'
container_name: node-sdc
tty: true
#restart: always
ports:
- "0.0.0.0:3000:3000"
- "0.0.0.0:4000:4000"
- "0.0.0.0:5000:5000"
- "0.0.0.0:8000:80"
volumes:
- .:/usr/src/app
yolov5-service:
build:
context: .
dockerfile: Dockerfile-yolo
environment:
CHOKIDAR_USEPOLLING: 'true'
container_name: yolo
tty: true
#restart: always
ports:
- "0.0.0.0:8888:5000"
volumes:
- .:/usr/src/app/server
- ./training_data:/usr/src/coco
- ./yolo_runs:/usr/src/app/runs
mongo-sdc-service:
# image: mongo:4.2-bionic
image: mongo:5.0-focal
# restart: always
container_name: mongo-sdc
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 1004
MONGO_INITDB_DATABASE: sdc
volumes:
- mongo-sdc-storage:/data/db
ports:
- 27020:27017
volumes:
mongo-sdc-storage:
CodePudding user response:
You should expose both port in Dockerfile
EXPOSE 5000
EXPOSE 8888
In docker-compose file use this config
ports:
- target: 5000
published: 5000
protocol: tcp
mode: host
- target: 8888
published: 8888
protocol: tcp
mode: host
CodePudding user response:
Each container is added to the same docker network from your compose. Now since it resides on the same network the PORT that you need to query is 5000 from within your node-sdc-service and not 8888. more information can be found here https://docs.docker.com/compose/networking/#links