Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scaling Node with Docker + Nginx

Scaling Node with Docker + Nginx

In this talk we present solutions to scale node applications by leveraging Docker and Nginx.

Nils De Moor

March 12, 2014
Tweet

More Decks by Nils De Moor

Other Decks in Programming

Transcript

  1. Belgian node.js User Group Nils De Moor - @ndemoor -

    woorank.com Scaling Node with Docker + Nginx
  2. • Nils De Moor • CTO & co-founder at WooRank

    • #node #mongo #ansible #aws #devops #docker About me
  3. • LXC Containers • “Chroot on steroids” • AUFS •

    layered view on merged directories • copy-on-write What and how?
  4. FROM ubuntu # make sure the package repository is up

    to date RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update # install memcached RUN apt-get install -y memcached # run as user daemon (memcached doesn't allow to run as root) USER daemon # expose memcached port EXPOSE 11211 # Launch memcached when launching the container # CMD [ "memcached" ] ENTRYPOINT ["memcached"]
  5. FROM ubuntu MAINTAINER Nils De Moor RUN echo "deb http://archive.ubuntu.com/ubuntu

    precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get install -y python-software-properties software-properties-common RUN add-apt-repository ppa:chris-lea/node.js RUN apt-get update RUN apt-get install -y nodejs CMD [ "node" ]
  6. FROM njugbe/node:0.10.26 MAINTAINER Nils De Moor ADD . /var/www RUN

    cd /var/www && npm install EXPOSE 3000 CMD [ "node", "/var/www/server.js" ]
  7. 0.1

  8. 0.1

  9. # Configuration for the server server { listen 80; location

    / { proxy_pass http://app_containers; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; } }
  10. #!/bin/sh IMAGE=$1 VERSION=$2 DOCKER_ID=`docker run \ -link memcache:mc \ -v

    /tmp/log/app:/var/log/app:rw \ -p 3000 \ -d \ $IMAGE:$VERSION` PORT=`sudo docker inspect $DOCKER_ID | grep HostPort | cut -d '"' -f 4 | head -1` cat >/etc/nginx/conf.d/app_containers.conf <<EOL upstream app_containers { server 127.0.0.1:${PORT}; } EOL echo "Version:\t$IMAGE:$VERSION\n Id:\t\t$DOCKER_ID\n Port:\t\t$PORT"
  11. • Deis - deployment and orchestration • Dokku - deployment

    • Fig - deployment • Flynn - deployment and orchestration • Shipyard - monitoring Community