nginx-proxy for more than one node app docker

Viewed 3487

i am trying nginx reverse proxy multiple container .

i have 2 container which have node add one listen on 8085 and other on 8086 i want them to access by

node.app1.com

node.app2.com

so i used jwilder/nginx-proxy:latest which will sit in fount of both of these container and will act as revers proxy . so here is my compose.yml file.


docker-compose.yml

version: "3"
services:
  node-proxy:
    build:  ./node-proxy
    container_name : node-proxy
    restart : always
    volumes:  
        -  /var/run/docker.sock:/tmp/docker.sock:ro
    ports:
      - 80:80
      - 443:443
  node-app1:
    build:  ./app1
    container_name : node-app1
    restart: always
    environment:
      VIRTUAL_HOST: node.app1.com
    depends_on:
      - node-proxy
  node-app2:
    build:  ./app2
    container_name : node-app2
    restart: always
    environment:
      VIRTUAL_HOST: node.app2.com
    depends_on:
      - node-proxy

./node-proxy/Dockerfile

FROM jwilder/nginx-proxy:latest

./app1/app1.js

var http = require("http");

http.createServer(function (request, response) {

   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World 1\n');
}).listen(8085);

./app1/Dockerfile

FROM node:6.11
WORKDIR /app2
COPY app1.js .
CMD node app1.js
Expose 8085

./app2/app2.js

var http = require("http");

http.createServer(function (request, response) {

   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World 2\n');
}).listen(8086);

./app2/Dockerfile

FROM node:6.11
WORKDIR /app2
COPY app2.js .
CMD node app2.js
Expose 8086

So when i do

docker-compose up 

all my containers are up and running

enter image description here

but when do node.app1.com --> it say's unknown host .

so to check wether request is coming to proxy i tryed calling http://localhost from browser and it says 503

enter image description here

i also checked nginx.config in side container by

enter image description here

docker exec -it node-proxy_id bash

cat /etc/nginx/conf.d/

and its there but i think when i do node.app1.com request not coming to proxy . i am not getting where i have missed , can some one help me out with this .

Thanks for your time

2 Answers
Related