arquitecturas-concurrentes / iasc-docker-compose-nginx-node-example

Small example of a node.js app using nginx as a load balancer using docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iasc-docker-compose-nginx-node-example

Small example of a node.js app using nginx as a load balancer using docker

Pre-requisites

  • 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.

Building an image, for eg. the app

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

alt text

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

Using compose

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

About

Small example of a node.js app using nginx as a load balancer using docker


Languages

Language:Dockerfile 56.1%Language:JavaScript 37.5%Language:Shell 6.4%