Code Monkey home page Code Monkey logo

docker-nginx-lb-serf's Introduction

This is a container that uses Nginx as a Load Balancer for a Node.js application using Serf for auto-discovery of new nodejs containers.

It does not depend on Node.js but the serf-member-join.sh script will detect any node.js (or web) container available to Serf and add it to the load balancer.

Nginx will not check if a host is alive, that's Serf's job.

The nginx.conf file it's configured to serve static files, but it needs access to the static files at /var/www so make sure you link the volume with your application when running the container.

I'm using fig to start the container, this is the important part:

serf:
  image: luis/serf
  ports:
   - "7373"
   - "7946"
web:
  build: .
  links:
   - mongodb:mongodb
   - elasticsearch:elasticsearch
   - serf:serf
  expose:
   - "3000"
  volumes:
   - "/var/www:/var/www"
   - "/var/log/docker:/var/log/supervisor"
   - "/var/files:/var/files"
  environment:
   MONGODB_DATABASE: somedb
   NODE_ENV: production
lb:
  image: luis/nginx-lb
  ports:
    - "80:80"
  links:
    - serf:serf
  volumes:
   - "path-to-some-default.conf:/etc/nginx/sites-enabled"
   - "/var/www:/var/www"
   - "/var/log/docker:/var/log/supervisor"
   - "/var/files:/var/files"

As you can see, both my load balancer and web application links to the serf container. I'm also mounting the same volumes for both my web container and the lb container. Finally, the web container will be built using a Dockerfile that I'm including in my application.

Note: You can mount /etc/nginx/sites-enabled and include a default configuration, I'm adding in config/default-example.conf the file I'm using but you can change it if you want to. This fill will be added to the container in case you don't mount the directory. The file MUST be named "default" so the scripts can add new containers as soon as serf detects them

docker-nginx-lb-serf's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.