Small example of a node.js app using nginx as a load balancer using docker
- Have an account on docker hub, if you want to push the docker images created
- install the docker and docker-compose applications, using apt-get, brew or related to your OS.
on the app folder you can build up the image by doing:
docker build -t <your username>/node-pong-app .
execute it by doing
docker run -p 49160:5000 -d <your username>/node-pong-app
and getting the status by
docker ps
also you can see the logs by doing
docker logs 99cb44d439be
in these examples 99cb44d439be is the container id.
you can enter the docker image by doing
docker exec -it 99cb44d439be /bin/bash
We can use the compose by building using the cmd
docker-compose build
if you want to set up more than one app then we need to change the nginx config
upstream app_servers {
server iasc-docker-compose-nginx-node-example_app_1:5000;
server iasc-docker-compose-nginx-node-example_app_2:5000;
server iasc-docker-compose-nginx-node-example_app_3:5000;
server iasc-docker-compose-nginx-node-example_app_4:5000;
}
then scale it accordingly
docker-compose up --scale app=4
and then bringing the services up
docker-compose up