SlideShare a Scribd company logo
How many…
are using Docker in production?
are using Docker in development?
are here to see if Docker is the right tool for them?
#DesertCodeCamp @wfbutton
In this session:
• Docker best practices
• Deploying node.js
• Creating Docker resources
• Performance optimizing
• Repeatable
#DesertCodeCamp @wfbutton
http://bit.ly/dcc-docker
#DesertCodeCamp @wfbutton
https://github.com/nodejs/docker-node/blob/master/docs/
BestPractices.md
#DesertCodeCamp @wfbutton
Our humble Dockerfile
• Actually called
“Dockerfile”
• In the same directory
as our code
#DesertCodeCamp @wfbutton
…gets a Nodejs version
from node:4.4.7
#DesertCodeCamp @wfbutton
Run as
non-root
Limit exposure when
compromised
#DesertCodeCamp @wfbutton
…gets a user
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
#DesertCodeCamp @wfbutton
…gets and a home
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs
#DesertCodeCamp @wfbutton
…gets a production env
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs

ENV NODE_ENV=production
#DesertCodeCamp @wfbutton
docker-compose
• Defines our container
• services, networks,
volumes
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
build: .
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
build: .
ports:

- '3000:3000'
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
build: .
ports:

- ‘3000:3000’
volumes:

- .:/home/nodejs/app
back to the Dockerfile
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs

ENV NODE_ENV=production
USER nodejs

CMD ["node", "server.js"]
This isn’t bad, and it will work…
but we can improve it!
#DesertCodeCamp @wfbutton
What if…
I copied these into the container?
#DesertCodeCamp @wfbutton
As a matter of fact…
• it will create the node_modules folder
• thanks to Docker caching and build layers, if
package.json and npm-shrinkwrap.json don’t
change:
• the layer gets re-used
• Result: faster deploys because you don’t have to
wait for npm install to run
#DesertCodeCamp @wfbutton
there is a catch…
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs

ENV NODE_ENV=production
COPY package.json npm-shrinkwrap.json $HOME/app/

RUN chown -R nodejs:nodejs $HOME/*

USER nodejs

RUN npm install
CMD ["node", "server.js"]
#DesertCodeCamp @wfbutton
docker-compose.yml
app:

mem_limit: 300m

memswap_limit: 1g
build: .
ports:

- ‘3000:3000’
volumes:

- .:/home/nodejs/app

- /home/nodejs/app/node_modules
#DesertCodeCamp @wfbutton
docker-compose build
#DesertCodeCamp @wfbutton
How’d we do?
We set our environment variables in the Dockerfile.
#DesertCodeCamp @wfbutton
How’d we do?
We created a user ‘nodejs’ and launch our app with it.
#DesertCodeCamp @wfbutton
How’d we do?
We limited the memory and swap on our container to
prevent it from stealing resources.
#DesertCodeCamp @wfbutton
How’d we do?
We created our start command inside the container.
#DesertCodeCamp @wfbutton
Test-drive
docker-compose up
#DesertCodeCamp @wfbutton
Remember the .:/home?
• The dot is a local reference.
• On a remote server you can’t
reference local folders
• Use a file system reference
local to the Docker host
#DesertCodeCamp @wfbutton
Going further
• Deploy script reduces
deployments to a single
command
• While simple to start, they can
grow with your needs
• Imagine new developer on-
boarding
#DesertCodeCamp @wfbutton
Hey new guy,
clone the repo and type ‘npm deploy’
#DesertCodeCamp @wfbutton
The Keys to the Castle
Don’t be ridiculous, we’re not doing that…
#DesertCodeCamp @wfbutton
https://www.docker.com/sites/default/files/RA_CI%20with
%20Docker_08.25.2015.pdf
or just
Google “deploy
Docker with
Jenkins”
#DesertCodeCamp @wfbutton
Testing
• Sadly, still an area where Docker needs work
• Bundle test suite (and test data) into image
• Rely on external integration style tests for validation
#DesertCodeCamp @wfbutton
• Goal of using best practices
• Pinned version
• non-root user
• environment variables
• memory limits
• Caching layers for performance
• Locally vs. Remote Deploys
• Single command deployments
• Automated deployments
• Testing
#DesertCodeCamp @wfbutton
Try it out.
Use the repo as a basic starter kit.
If it works, awesome!
If it doesn’t, fail fast!
#DesertCodeCamp @wfbutton

More Related Content

What's hot (20)

PDF
Enabling Hybrid Workflows with Docker/Mesos @Orbitz
Steve Hoffman
 
PPTX
Automating Software Development Life Cycle - A DevOps Approach
Akshaya Mahapatra
 
PPTX
Romulus crisan + radu pascal click'n'deploy
Codecamp Romania
 
PDF
Superb Supervision of Short-lived Servers with Sensu
Paul O'Connor
 
PDF
Docker: automation for the rest of us
Jérôme Petazzoni
 
PDF
Test Automation Infrastructure with Containers
Manoj Kumar Kumar
 
PPTX
Automate your Development Environment with Vagrant & Chef
Michael Lihs
 
PDF
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Henning Jacobs
 
PDF
Testing as a container
Irfan Ahmad
 
PDF
CI/CD Using Ansible and Jenkins for Infrastructure
Faisal Shaikh
 
PDF
DevOps with Serverless
Yan Cui
 
PPTX
DevOps In Action
David Strebel
 
PDF
COSCUP 2017 - infrastructure As Code
smalltown
 
PDF
Democratizing Development - Scott Gress
Docker, Inc.
 
PDF
Achieving Continuous Delivery: An Automation Story
jimi-c
 
PDF
DevOps For Small Teams
Joe Ferguson
 
PPTX
Zero to Continuous Delivery on Google Cloud
James Heggs
 
PDF
You Don't Have to Start Over! A Practical Guide for Adopting Docker in the En...
Docker, Inc.
 
PDF
05.10.2017 AWS User Group Meetup - FALLACIES OF DISTRIBUTED COMPUTING WITH KU...
Zalando adtech lab
 
PDF
Serverless in Production, an experience report (AWS UG South Wales)
Yan Cui
 
Enabling Hybrid Workflows with Docker/Mesos @Orbitz
Steve Hoffman
 
Automating Software Development Life Cycle - A DevOps Approach
Akshaya Mahapatra
 
Romulus crisan + radu pascal click'n'deploy
Codecamp Romania
 
Superb Supervision of Short-lived Servers with Sensu
Paul O'Connor
 
Docker: automation for the rest of us
Jérôme Petazzoni
 
Test Automation Infrastructure with Containers
Manoj Kumar Kumar
 
Automate your Development Environment with Vagrant & Chef
Michael Lihs
 
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Henning Jacobs
 
Testing as a container
Irfan Ahmad
 
CI/CD Using Ansible and Jenkins for Infrastructure
Faisal Shaikh
 
DevOps with Serverless
Yan Cui
 
DevOps In Action
David Strebel
 
COSCUP 2017 - infrastructure As Code
smalltown
 
Democratizing Development - Scott Gress
Docker, Inc.
 
Achieving Continuous Delivery: An Automation Story
jimi-c
 
DevOps For Small Teams
Joe Ferguson
 
Zero to Continuous Delivery on Google Cloud
James Heggs
 
You Don't Have to Start Over! A Practical Guide for Adopting Docker in the En...
Docker, Inc.
 
05.10.2017 AWS User Group Meetup - FALLACIES OF DISTRIBUTED COMPUTING WITH KU...
Zalando adtech lab
 
Serverless in Production, an experience report (AWS UG South Wales)
Yan Cui
 

Viewers also liked (8)

ODP
Introduction to Docker for NodeJs developers at Node DC 2/26/2014
lenworthhenry
 
PDF
Nodejs OC Docker and Node
Jeff Horn
 
PDF
Building a SaaS with Nodejs, Docker, and CoreOS
Ross Kukulinski
 
PDF
Shipping NodeJS with Docker and CoreOS
Ross Kukulinski
 
PDF
Разработка Enterprise-приложения на основе Spring Framework
CUSTIS
 
PPSX
Agile — это не то, что ты думаешь
Vasiliy Cheptsov
 
PPSX
Agile по Суворову
Vasiliy Cheptsov
 
PDF
Efficient use of NodeJS
Yura Bogdanov
 
Introduction to Docker for NodeJs developers at Node DC 2/26/2014
lenworthhenry
 
Nodejs OC Docker and Node
Jeff Horn
 
Building a SaaS with Nodejs, Docker, and CoreOS
Ross Kukulinski
 
Shipping NodeJS with Docker and CoreOS
Ross Kukulinski
 
Разработка Enterprise-приложения на основе Spring Framework
CUSTIS
 
Agile — это не то, что ты думаешь
Vasiliy Cheptsov
 
Agile по Суворову
Vasiliy Cheptsov
 
Efficient use of NodeJS
Yura Bogdanov
 
Ad

Similar to Deploy Nodejs on Docker (20)

PDF
Container Days
Patrick Mizer
 
PDF
ContainerDays NYC 2015: "Easing Your Way Into Docker: Lessons From a Journey ...
DynamicInfraDays
 
PDF
Getting up and running with Docker
Nils De Moor
 
PDF
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
PDF
Docker dev, test & production (afas)
Wouter Lagerweij
 
PPTX
Beginners Guide to Kontena
Lauri Nevala
 
PPTX
Beginners Guide To Kontena
Kontena, Inc.
 
PPTX
Real World Experience of Running Docker in Development and Production
Ben Hall
 
PDF
Docker workshop GDSC_CSSC
GDSC UofT Mississauga
 
PDF
DCSF 19 Node.js Rocks in Docker for Dev and Ops
Docker, Inc.
 
PDF
Node.js Rocks in Docker for Dev and Ops
Bret Fisher
 
PPTX
DockerCon 15 Keynote - Day 2
Docker, Inc.
 
PDF
codemotion-docker-2014
Carlo Bonamico
 
PPTX
From Docker to Production - ZendCon 2016
Chris Tankersley
 
PDF
Docker: A New Way to Turbocharging Your Apps Development
msyukor
 
PDF
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion
 
PPTX
Start your adventure with docker
Sagar Dash
 
PDF
Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017
Usersnap
 
PDF
[@NaukriEngineering] Docker 101
Naukri.com
 
PPTX
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
Container Days
Patrick Mizer
 
ContainerDays NYC 2015: "Easing Your Way Into Docker: Lessons From a Journey ...
DynamicInfraDays
 
Getting up and running with Docker
Nils De Moor
 
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
Docker dev, test & production (afas)
Wouter Lagerweij
 
Beginners Guide to Kontena
Lauri Nevala
 
Beginners Guide To Kontena
Kontena, Inc.
 
Real World Experience of Running Docker in Development and Production
Ben Hall
 
Docker workshop GDSC_CSSC
GDSC UofT Mississauga
 
DCSF 19 Node.js Rocks in Docker for Dev and Ops
Docker, Inc.
 
Node.js Rocks in Docker for Dev and Ops
Bret Fisher
 
DockerCon 15 Keynote - Day 2
Docker, Inc.
 
codemotion-docker-2014
Carlo Bonamico
 
From Docker to Production - ZendCon 2016
Chris Tankersley
 
Docker: A New Way to Turbocharging Your Apps Development
msyukor
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion
 
Start your adventure with docker
Sagar Dash
 
Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017
Usersnap
 
[@NaukriEngineering] Docker 101
Naukri.com
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
Ad

More from Will Button (8)

PDF
Build an Infra Product with AWS Fargate
Will Button
 
PDF
Effective Telepresence and Remote Collaboration
Will Button
 
PDF
Traxticsearch
Will Button
 
PPTX
No More Mr. Nice Guy The MEAN Stack
Will Button
 
PPTX
Practical MongoDB
Will Button
 
PPTX
Mongo Sharding: Case Study
Will Button
 
PPTX
Mongoose and MongoDB 101
Will Button
 
PPTX
Mongo db mug_2012-02-07
Will Button
 
Build an Infra Product with AWS Fargate
Will Button
 
Effective Telepresence and Remote Collaboration
Will Button
 
Traxticsearch
Will Button
 
No More Mr. Nice Guy The MEAN Stack
Will Button
 
Practical MongoDB
Will Button
 
Mongo Sharding: Case Study
Will Button
 
Mongoose and MongoDB 101
Will Button
 
Mongo db mug_2012-02-07
Will Button
 

Recently uploaded (20)

PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Import Data Form Excel to Tally Services
Tally xperts
 
Human Resources Information System (HRIS)
Amity University, Patna
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 

Deploy Nodejs on Docker