people of serverfault. Started dabbling in docker with nginx and nodejs, and I'm having a bit of trouble figuring out how to debug my issue here. I'm running 3x nodejs containers and 1x nginx load balancer in front of them.
I can spin up the docker-compose successfully with docker-compose up, but when accessing localhost:8080 I get an nginx 502 with the following error in the console, repeated 3 times (for each node backend):
loadbalancer_1 | 2019/10/05 11:40:31 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: MY_CLIENT_IP, server: localhost, request: "GET / HTTP/1.1", upstream: "http://172.19.0.4:3000/", host: "MY_PUBLIC_IP:8080"
This is my folder structure:
├── backend
│ ├── Dockerfile
│ └── src
│ ├── index.js
│ └── package-lock.json
├── docker-compose.yml
└── load-balancer
├── Dockerfile
└── nginx.conf
./docker-compose.yml
version: '3.2'
services:
backend1:
build: ./backend
tty: true
volumes:
- './backend/src:/backend-dir-inside-container'
backend2:
build: ./backend
tty: true
volumes:
- './backend/src:/backend-dir-inside-container'
backend3:
build: ./backend
tty: true
volumes:
- './backend/src:/backend-dir-inside-container'
loadbalancer:
build: ./load-balancer
tty: true
links:
- backend1
- backend2
- backend3
ports:
- '8080:8080'
volumes:
backend:
./backend/Dockerfile
FROM node:boron
LABEL Joe Programmer
RUN mkdir -p /backend-dir-inside-container
WORKDIR /backend-dir-inside-container
FROM node:boron
LABEL Joe Programmer
RUN mkdir -p /backend-dir-inside-container
WORKDIR /backend-dir-inside-container
EXPOSE 3000
./loadbalancer/Dockerfile
FROM nginx
LABEL Joe Programmer
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
And this is my ./loadbalancer/nginx.conf
events { worker_connections 1024; }
http {
upstream localhost {
server backend1:3000;
server backend2:3000;
server backend3:3000;
}
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://localhost;
proxy_set_header Host $host;
}
}
}
Besides fixing this issue I'm looking to learn what exactly I'm doing wrong here. Thank you for any or all responses.