This document summarizes a webinar about building microservices using Node.js and Docker. It discusses creating a base Docker image with Node.js, building a simple Express microservice, running the microservice in a Docker container, building a Docker image from the container, and publishing the image to Docker Hub. The webinar covers Docker terminology and demonstrates each step through code examples to help developers learn how to containerize Node.js applications.
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
• A Docker platform for development teams.
• Build, Run & Test Docker containers
• Launch any PR, Commit or Branch in
seconds
@codefresh
5. 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
6. 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
7. 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/
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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