0

I use a docker-compose file with 3 service (node-red, mosquitto and mongo) and and I want use nginx as load balancer of node-red service:

version: '2.2'

networks:
  Platform-Network:
    name: IoT-Network

volumes:
  Platform:
  MQTT-broker:
  DataBase:
  Nginx:

services: 

  Platform:
    image: custom-node-red:latest
    networks:
      - Platform-Network
    restart: always
    volumes:
      - ./node-red:/data
    # depends_on:
    #   - Nginx
  
  MQTT-broker:
    container_name: mosquitto
    image: eclipse-mosquitto
    ports:
      - "192.168.100.101:1883:1883"
    networks:
      - Platform-Network
    restart: always
    depends_on:
      - Platform
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log 
  
  DataBase:
    container_name: mongodb
    image: mongo
    ports:
      - "8083:27017"
    networks:
      - Platform-Network
    restart: always
    depends_on:
      - Platform
    volumes:
      - ./mongodb/data:/data/db
      - ./mongodb/backup:/data/backup
      - ./mongodb/mongod.conf:/etc/mongod.conf
      - ./mongodb/log:/var/log/mongodb/

  Nginx:
    container_name: nginx
    image: nginx
    ports: 
      - "4000:4000"
    depends_on:
      - Platform
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    restart: always

Nginx config file is:

user nginx;
events {
    worker_connections 1000;
}
http {
    upstream platform {
        server platform_1:1880;
        server platform_2:1880;
        server platform_3:1880;
    }
    server {
        listen [::]:4000;
        listen 4000;
        location / {
            proxy_pass http://platform;
        }
    }
}

I run my service with docker-compose -f platform.yaml up -d --scale Platform=3 and containers up as show in this .But as showen in above image, nginx dosnt up. Nginx container log get this error and i can't resolve it.

miladmrm
  • 1
  • 1

1 Answers1

0

Your nginx service also need to join the same network as Platform:

Nginx:
  container_name: nginx
  image: nginx
  ports: 
    - "4000:4000"
  depends_on:
    - Platform
  volumes:
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
  restart: always
  networks: # add this
    - Platform-Network 
Leo
  • 121
  • 3