Containers #101 Building a micro-service using Node.js & Docker July 15
About the meetup • A series of 30 min webinars + 10 min Q&A • Hands On • Session are recorded • Suggested topics and presenters are welcome
About me • Developer, entrepreneur and technology enthusiast • Live in the Silicon Valley since 2008 • Founder and CEO of Codefresh • Member of the Node.js foundation @RazielTabib
About codefresh • A Docker platform for development teams. • Build, Run & Test Docker containers • Launch any PR, Commit or Branch in seconds @codefresh
What we will see today • Create base Docker image • Build a simple micro-service • Run our micro-service inside a container • Create a Docker image from an existing container • Publish our image in Docker hub ubuntu Node.js base image micro-service micro-service micro-service image
Terminology Docker Images Blueprints of our application Docker Container Created from docker images and are real instances of our application Docker Daemon Building, running and distributing Docker containers Docker Client Run on our local machine and connect to the daemon Docker Hub A registry of docker images https://www.airpair.com/node.js/posts/getting-started-with-docker-for-the-nodejs-dev
Terminology Docker Images Blueprints of our application Docker Container Created from docker images and are real instances of our application Docker Daemon Building, running and distributing Docker containers Docker Client Run on our local machine and connect to the daemon Docker Hub A registry of docker images http://thenewstack.io/understanding-the-docker-cache-for-faster-builds/
Create a base image • Check boot2docker version & status 8 Raziels-Air:~ RazielMac$ boot2docker version • search, pull & run ubuntu image Raziels-Air:~ RazielMac$ boot2docker status Raziels-Air:~ RazielMac$ docker search ubuntu Raziels-Air:~ RazielMac$ docker run -it ubuntu ./bin/bash • Install node Raziels-Air:~ apt-get update Raziels-Air:~ apt-get install nodejs Raziels-Air:~ apt-get install nodejs-legacy ubuntu Node.js base image Raziels-Air:~ apt-get install npm • Create a Docker image Raziels-Air:~ docker commit –a “razielt” CONTAINER-ID IMAGE-NAME:tag
Build a simple micro-service • Create a skeleton using express generator 9 Raziels-Air:~ RazielMac$ npm install –g express-generator • Add an api.js with simple get function Raziels-Air:~ RazielMac$ express microservice • Run micro-service locally Raziels-Air:~ npm install Raziels-Air:~ npm start /* GET greeting. */ router.get('/sayhello', function(req, res) { res.send('Hello meetup members'); }); micro-service
Run inside a container • Get our local directory path 10 Raziels-Air:~ pwd • Run a container with volume mounting and port mapping • Copy micro-service to container Raziels-Air:~ cp –r host /microservice Raziels-Air:~ cd microservice ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker run –it –v HOSTFOLDER:CONTAINERFOLDER –p HOSTPORT:CONTAINERPORT IMAGENAME:TAG Raziels-Air:~ npm start
Create & run docker image • Create an image 11 Raziels-Air:~ docker commit CONTAINERID, IMAGENAME:TAG • Run micro-service in the background ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker run –d –w /microservice –p 9000:3000 IMAGENAME npm start micro-service image
Push to Docker hub • Login 12 Raziels-Air:~ docker login • Push out image ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker tag nodejs-microservice your_dockerhub_user/nodejs-microservice micro-service image Raziels-Air:~ RazielMac$ docker push your_dockerhub_user/nodejs-microservice
What we did today • Create base Docker image • Build a simple micro-service • Run our micro-service inside a container • Create a Docker image from an existing container • Publish our image in Docker hub ubuntu Node.js base image micro-service micro-service micro-service image
additional resources • Codefresh blog blog.codefresh.io • New name* Containers #101 http://www.meetup.com/Containers-101-online-meetup/ • ContainerNode http://www.meetup.com/ConatinerNode • Docker Online meetup (delivered by Docker) http://www.meetup.com/Docker-Online-Meetup/ @codefresh
Questions? raziel@codefresh.io www.codefresh.io @RazielTabib Sign up to our beta @ www.codefresh.io

Containers #101 Meetup: Building a micro-service using Node.js and Docker - Part #1

  • 1.
    Containers #101 Building amicro-service using Node.js & Docker July 15
  • 2.
    About the meetup •A series of 30 min webinars + 10 min Q&A • Hands On • Session are recorded • Suggested topics and presenters are welcome
  • 3.
    About me • Developer,entrepreneur and technology enthusiast • Live in the Silicon Valley since 2008 • Founder and CEO of Codefresh • Member of the Node.js foundation @RazielTabib
  • 4.
    About codefresh • ADocker platform for development teams. • Build, Run & Test Docker containers • Launch any PR, Commit or Branch in seconds @codefresh
  • 5.
    What we willsee today • Create base Docker image • Build a simple micro-service • Run our micro-service inside a container • Create a Docker image from an existing container • Publish our image in Docker hub ubuntu Node.js base image micro-service micro-service micro-service image
  • 6.
    Terminology Docker Images Blueprints ofour application Docker Container Created from docker images and are real instances of our application Docker Daemon Building, running and distributing Docker containers Docker Client Run on our local machine and connect to the daemon Docker Hub A registry of docker images https://www.airpair.com/node.js/posts/getting-started-with-docker-for-the-nodejs-dev
  • 7.
    Terminology Docker Images Blueprints ofour application Docker Container Created from docker images and are real instances of our application Docker Daemon Building, running and distributing Docker containers Docker Client Run on our local machine and connect to the daemon Docker Hub A registry of docker images http://thenewstack.io/understanding-the-docker-cache-for-faster-builds/
  • 8.
    Create a baseimage • Check boot2docker version & status 8 Raziels-Air:~ RazielMac$ boot2docker version • search, pull & run ubuntu image Raziels-Air:~ RazielMac$ boot2docker status Raziels-Air:~ RazielMac$ docker search ubuntu Raziels-Air:~ RazielMac$ docker run -it ubuntu ./bin/bash • Install node Raziels-Air:~ apt-get update Raziels-Air:~ apt-get install nodejs Raziels-Air:~ apt-get install nodejs-legacy ubuntu Node.js base image Raziels-Air:~ apt-get install npm • Create a Docker image Raziels-Air:~ docker commit –a “razielt” CONTAINER-ID IMAGE-NAME:tag
  • 9.
    Build a simplemicro-service • Create a skeleton using express generator 9 Raziels-Air:~ RazielMac$ npm install –g express-generator • Add an api.js with simple get function Raziels-Air:~ RazielMac$ express microservice • Run micro-service locally Raziels-Air:~ npm install Raziels-Air:~ npm start /* GET greeting. */ router.get('/sayhello', function(req, res) { res.send('Hello meetup members'); }); micro-service
  • 10.
    Run inside acontainer • Get our local directory path 10 Raziels-Air:~ pwd • Run a container with volume mounting and port mapping • Copy micro-service to container Raziels-Air:~ cp –r host /microservice Raziels-Air:~ cd microservice ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker run –it –v HOSTFOLDER:CONTAINERFOLDER –p HOSTPORT:CONTAINERPORT IMAGENAME:TAG Raziels-Air:~ npm start
  • 11.
    Create & rundocker image • Create an image 11 Raziels-Air:~ docker commit CONTAINERID, IMAGENAME:TAG • Run micro-service in the background ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker run –d –w /microservice –p 9000:3000 IMAGENAME npm start micro-service image
  • 12.
    Push to Dockerhub • Login 12 Raziels-Air:~ docker login • Push out image ubuntu Node.js micro-service base image Raziels-Air:~ RazielMac$ docker tag nodejs-microservice your_dockerhub_user/nodejs-microservice micro-service image Raziels-Air:~ RazielMac$ docker push your_dockerhub_user/nodejs-microservice
  • 13.
    What we didtoday • Create base Docker image • Build a simple micro-service • Run our micro-service inside a container • Create a Docker image from an existing container • Publish our image in Docker hub ubuntu Node.js base image micro-service micro-service micro-service image
  • 14.
    additional resources • Codefreshblog blog.codefresh.io • New name* Containers #101 http://www.meetup.com/Containers-101-online-meetup/ • ContainerNode http://www.meetup.com/ConatinerNode • Docker Online meetup (delivered by Docker) http://www.meetup.com/Docker-Online-Meetup/ @codefresh
  • 15.