https://github.com/fdocr/nodejs-loadbalanced-dockercompose
Simple Node.js app with nginx as load balancer proxy and mongodb back managed via docker-compose
https://github.com/fdocr/nodejs-loadbalanced-dockercompose
Last synced: 12 months ago
JSON representation
Simple Node.js app with nginx as load balancer proxy and mongodb back managed via docker-compose
- Host: GitHub
- URL: https://github.com/fdocr/nodejs-loadbalanced-dockercompose
- Owner: fdocr
- Created: 2015-11-29T23:04:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-04T11:53:59.000Z (over 10 years ago)
- Last Synced: 2025-04-06T04:26:22.326Z (12 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Node.JS - Docker Compose - Nginx Proxy
This repo is an example use of docker-compose with a simple front Node.js app. I'm looking into diving as deep as possible into distributing workloads and this is my first attempt to practice with [docker-compose](https://docs.docker.com/compose/). The idea is to load balance the requests amongst multiple nodes behind a proxy. I used an amazing image from [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy) to dynamically reload the conf files of an nginx-proxy (that's the tricky part) of containers.
A blog post that explains slightly better and in depth can be [found at visualcosita.xyz](http://visualcosita.xyz/post/load-balancing-a-node-js-app-behind-nginx-proxy-managed-by-docker-compose/).
But in few words this is a slightly opinionated use of the Express template to hold a counter of hits based on ip addresses that request them, the idea came from [this python repo](https://github.com/bfirsh/compose-mongodb-demo) that is actually much more minimalist.
### Usage
`docker-compose up -d` should boot the proxy->front->mongodb properly (or execute `make`, all other commands in the Makefile where used for debugging).
To scale the front service run `docker-compose scale front=3`. Requests should be distributed to all three nodes, this can be verified executing `docker-compose logs` and querying to the url `curl front.IP_ADDRESS.xip.io` or in a browser.
I used `docker-machine` since I'm a Mac user, but the `docker-compose.yml` should support native Linux environments (the difference should be the IP address to query).