Docker Community Forums

Share and learn in the Docker community.

Access nodejs hosted in docker container in another container using web application

I have 3 containers running:

  1. nodejs 12.20.1
  2. openmrs with embedded tomcat 7
  3. mysql 5.7

OS: Ubuntu 16.04

tomcat container is able to connect to mysql . node is able to connect to mysql.

However when tomcat container tries to connect to node on a http request using node-container-id:3004/3333 as hostname:port OR node-container-internal-ip:3004/3333 as hostip:port , it keeps giving 404 error.

My docker-compose.yml is as follows:

version: ‘2.1’

services:

openmrs-referenceapplication-mysql:
restart: “always”
image: mysql:5.7
ports:
- 3333:3306
command: “mysqld --character-set-server=utf8 --collation-server=utf8_general_ci”
environment:
MYSQL_DATABASE: {MYSQL_DB:-openmrs} MYSQL_ROOT_PASSWORD: {MYSQL_ROOT_PASSWORD:-root-pass}
MYSQL_USER: {MYSQL_USER:-openmrs_user} MYSQL_PASSWORD: {MYSQL_PASSWORD:-my-pass}
healthcheck:
test: “exit 0”
volumes:
- openmrs-referenceapplication-mysql-data:/var/lib/mysql

openmrs-referenceapplication-node:
restart: “always”
image: node:12.20.1
depends_on :
- openmrs-referenceapplication-mysql
expose:
- “3004”
ports:
- “3009:3004”
links:
- openmrs-referenceapplication-mysql
- openmrs-referenceapplication
environment:
DB_DATABASE: {MYSQL_DB:-my-db} DB_HOST: openmrs-referenceapplication-mysql DB_USERNAME: {MYSQL_USER:-root}
DB_PASSWORD: ${MYSQL_PASSWORD:-my-pass}
volumes:
- openmrs-referenceapplication-node-data:/home/azureuser/my-dir
- ./Mydir:/Mydir
command: node ./Mydir/bin/www

openmrs-referenceapplication:
restart: “always”
image: openmrs/openmrs-reference-application-distro:2.8.0
depends_on:
- openmrs-referenceapplication-mysql
ports:
- “8001:8080”
links:
- openmrs-referenceapplication-mysql
environment:
DB_DATABASE: {MYSQL_DB:-openmrs} DB_HOST: openmrs-referenceapplication-mysql DB_USERNAME: {MYSQL_USER:-openmrs_user}
DB_PASSWORD: ${MYSQL_PASSWORD:-my-pass}
DB_CREATE_TABLES: ‘true’
DB_AUTO_UPDATE: ‘true’
MODULE_WEB_ADMIN: ‘true’
healthcheck:
test: [“CMD”, “curl”, “-f”, “http://localhost:8080/openmrs/”]
timeout: 20s
volumes:
- openmrs-referenceapplication-data:/usr/local/tomcat/.OpenMRS/
- /usr/local/tomcat/.OpenMRS/modules/ # do not store modules in data
- /usr/local/tomcat/.OpenMRS/owa/ # do not store owa in data
- ./webservices.rest-2.29.0.omod://usr/local/tomcat/.OpenMRS/modules/webservices.rest-2.29.0.omod
- /var/lib/tomcat8/webapps/ROOT.war:/usr/local/tomcat/webapps/ROOT

volumes:
openmrs-referenceapplication-mysql-data:
openmrs-referenceapplication-data:
openmrs-referenceapplication-node-data:

Any idea what am I missing?

Thanks

Satyadeep

I solved it by using the correct port-IP combination.

Thanks