Docker swarm sample with NodeJS app on Hyper-V
- This sample is using Hyper-V
git clone https://github.com/wswijaya/docker-swarm-node-app.git
docker build -t <your docker id>/node-app-sample .
docker push <your docker id>/node-app-sample
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm3
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm2
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm3
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm4
docker-machine ssh myvm1 "docker swarm init"
docker-machine ssh myvm1 "docker swarm join-token manager"
docker-machine ssh myvm3 "docker swarm join --token <token> <ip>:<port>"
docker-machine ssh myvm4 "docker swarm join --token <token> <ip>:<port>"
docker-machine ssh myvm1 "docker swarm join-token worker"
docker-machine ssh myvm2 "docker swarm join --token <token> <ip>:<port>"
docker-machine scp docker-compose-node-app.yml myvm1:~
docker-machine ssh myvm1 "docker stack deploy -c docker-compose-node-app.yml nodeapplab"
docker-machine ssh myvm1 "docker stack ps nodeapplab"
- Node Web App:
http://<ip>:4000
orhttp://<ip>:4000/api
- Docker Visualizer:
http://<ip>:9090
docker-machine ssh myvm1 "docker stack rm nodeapplab"
docker-machine ssh myvm1 "docker stack rm nodeapplab"
docker-machine ssh myvm2 "docker swarm leave"
docker-machine ssh myvm3 "docker swarm leave --force"
docker-machine ssh myvm4 "docker swarm leave --force"
docker-machine ssh myvm1 "docker swarm leave --force"
Installation steps for HAProxy on Ubuntu -> https://www.digitalocean.com/community/tutorials/how-to-use-haproxy-to-set-up-http-load-balancing-on-an-ubuntu-vps
Sample config file /etc/haproxy/haproxy.cfg
global
daemon
maxconn 200
defaults
mode http
timeout connect 5000ms
timeout client 10000ms
timeout server 10000ms
frontend http-in
bind *:9090
default_backend servers
backend servers
server vm1 <ip>:<port> maxconn 40
server vm3 <ip>:<port> maxconn 40
server vm4 <ip>:<port> maxconn 40