SlideShare a Scribd company logo
Node.js in a Docker Container
Lenworth Henry (lenworth.henry@gmail.com)
What is Docker
●

●

Docker is an easy way to create a lightweight
container from any application
The same container you use in development
can be scaled to production on any platform
that supports Linux Containers (Amazon, VMs,
etc)
What can you do with Docker
●

Software distribution (app + dependencies)
–

e.g. NodeJs web apps (app+node+mongo+redis)

●

Fast spin-up VMs (no booting)

●

Automated testing and continuous integration/deployment.

●

●

Deploying and scaling databases and back-end services
in a service-oriented environment.
Document what components you need to run your
application
Why did I seek out Docker
●

●

●

Every time a new framework or library was
added to our code base the developers got
out of sync and we lost productivity
We needed a way to synchronize our
development environments
I also needed a way to keep track of all the
components that we were using in our
application (i.e. not use history to tell what I
have installed)
Why not Vagrant
●

●

●

Vagrant requires each machine to have
VM software like Virtuabox
Vagrant is not designed for creating
containers for production because of
all the overhead
Vagrant wasn't any easier to configure
than docker, but, the container footprint
was larger
What  you will need
●

A workstation running Linux kernel 3.8
or greater
–

●

Docker containers can run inside VMs like
Virtuabox, but, as Linux containers they
are made for Linux

Knowledge of how to configure your
application on bare hardware
–

There is lots of help for this
Getting Started With Docker
Simple Docker Example
Docker speak
●

●

●

A container is a running instance of an
image.
You create an image starting with one of
the images found on the index and
adding any customizations either from
inside the running container or using a
Dockerfile
Dockerfile-->(build)-->Image---(run)->Container
Two work­flows with docker
●

Using commits
–
–

Connect to the shell of the base image and add whatever software,
customizations and your source (e.g. pull a git remote repository)

–

Commit to a new image

–
●

Run a base image

Run that image

Using Dockerfile
–

Create a dockerfile that includes all your configurations,
customizations and access to your source

–

This can all be pulled down from git to a different workstation

–

This is the most reliable option since your Dockerfile should be
rewritten that you can recreate the image with one command.
How to create a Docker File
●

If you don't remember all the packages
you installed then you can launch a
shell using a base image and then run
all the steps. Each step can be copied
to the docker file as a “RUN” command
Shell for Your Container
●

Once a docker image has been
created you can run it and enter the
bash shell using this command:
–

sudo docker run -t -i --rm ubuntu bash
Docker gotchas
●

You can only run one command or entrypoint for a container
–
–

●

●

You only have one cmd or entrypoint. Only one will get executed.
You must create a start script or use something like supervisord

If you change your source on the client you have to rebuild the image to see
those changes on the container.
You can't have long running processes in your Dockerfile
–

Each step is meant to execute and complete

–

Daemon like functionality should be executed when the container is running
Two containers
●

●

●

DB container is separate because it
rarely changes
The Node app resides in its own
container
Communication is enabled between
the two containers using linking
–

Linking works the same in production
environment
Example MEAN Stack app
●

MongoDB, Express, Angular and Node
–

Uses PassPortJS for authentication
Need to start multiple 
processes?
●

●

Each Dockerfile will have only one
entry point
Two options:
–

Create your own shell script that starts up
the processes and call that using a CMD
or ENTRYPOINT

–

Use supervisord
Example supervisord.conf
Helpful Docker commands 
●

logs (sudo docker logs @containerid)
–

●

Gives a print out of the tty after running

ps (sudo docker ps)
–
–

●

Shows you all running containers
Containers running in daemon mode will show
up here for as long as they are running

stop (sudo docker stop @containerid)
–

Stops a running container
Docker Tips
●

Only run in daemon mode (-d) if you have run
it without -d to see if there are any problems
with your configuration
–

●

You will not see errors printed out to stdout while
trying to load the container

Watch your disk space while creating images
and containers
–

Docker creates intermediate containers that can
quickly eat up disk space

–

Use the -rm=true when building
Questions and Helpful Links
●

●

●

●

Main Docker Site:
https://docs.docker.io/
Index Site (Prebuilt image search):
https://index.docker.io/

How to cleanup docker disk usage:
http://sosedoff.com/2013/12/17/cleanup-docker-cont

Docker Networking Details:
https://blog.codecentric.de/en/2014/01/docker-netwo

More Related Content

PDF
Docker
PDF
Docker mentorweek
PDF
Scale Big With Docker — Moboom 2014
PPTX
Docker session III: Dockerfile
ODP
Docker Basics
PPTX
Docker session II: Introduction to Docker
PPTX
Docker session I: Continuous integration, delivery and deployment
PDF
Docker for developers
Docker
Docker mentorweek
Scale Big With Docker — Moboom 2014
Docker session III: Dockerfile
Docker Basics
Docker session II: Introduction to Docker
Docker session I: Continuous integration, delivery and deployment
Docker for developers

What's hot (20)

PDF
Docker introduction - Part 1
PDF
Meetup 05 27-2015
PPTX
Docker Compose: Docker Configuration for the Real World
PPTX
Introduction to Docker - Getting Started with Docker
ODP
Docker. Micro services for lazy developers
PDF
Sep Nasiri "Upwork PHP Architecture"
PPTX
Building CLI Applications with Golang
PPTX
Academy PRO: Docker. Part 4
PDF
Introduction to Docker Container
PDF
Boston Code Dojo - Docker meetup slides
PPTX
docker compose
PDF
Moving to Docker... Finally!
PDF
Docker 101
PDF
Rkt Container Engine
PDF
Docker for developers
PDF
Docker cheat-sheet
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
PDF
Orchestration of docker containers at scale
Docker introduction - Part 1
Meetup 05 27-2015
Docker Compose: Docker Configuration for the Real World
Introduction to Docker - Getting Started with Docker
Docker. Micro services for lazy developers
Sep Nasiri "Upwork PHP Architecture"
Building CLI Applications with Golang
Academy PRO: Docker. Part 4
Introduction to Docker Container
Boston Code Dojo - Docker meetup slides
docker compose
Moving to Docker... Finally!
Docker 101
Rkt Container Engine
Docker for developers
Docker cheat-sheet
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Orchestration of docker containers at scale
Ad

Similar to Introduction to Docker for NodeJs developers at Node DC 2/26/2014 (20)

PDF
Docker
PPTX
Docker presentation
PPTX
Docker 101
PDF
Up and running with docker
PPTX
Dockers and containers basics
PPTX
docker technology in INTERNET WORLD.pptx
PDF
Docker up and Running For Web Developers
PDF
Docker Up and Running for Web Developers
PDF
Dockercon 23 - Getting started with Docker
PPTX
Introduction to Docker
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
PPTX
Virtualization, Containers, Docker and scalable container management services
PDF
docker.pdf
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PPTX
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
PDF
Docker in a JS Developer’s Life
PDF
Agile Brown Bag - Vagrant & Docker: Introduction
PDF
PPTX
Start your adventure with docker
PPTX
Powercoders · Docker · Fall 2021.pptx
Docker
Docker presentation
Docker 101
Up and running with docker
Dockers and containers basics
docker technology in INTERNET WORLD.pptx
Docker up and Running For Web Developers
Docker Up and Running for Web Developers
Dockercon 23 - Getting started with Docker
Introduction to Docker
Primi passi con Docker - ItalianCoders - 12-01-2021
Virtualization, Containers, Docker and scalable container management services
docker.pdf
Docker and containers - Presentation Slides by Priyadarshini Anand
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Docker in a JS Developer’s Life
Agile Brown Bag - Vagrant & Docker: Introduction
Start your adventure with docker
Powercoders · Docker · Fall 2021.pptx
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
The AUB Centre for AI in Media Proposal.docx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx

Introduction to Docker for NodeJs developers at Node DC 2/26/2014

  • 1. Node.js in a Docker Container Lenworth Henry (lenworth.henry@gmail.com)
  • 2. What is Docker ● ● Docker is an easy way to create a lightweight container from any application The same container you use in development can be scaled to production on any platform that supports Linux Containers (Amazon, VMs, etc)
  • 3. What can you do with Docker ● Software distribution (app + dependencies) – e.g. NodeJs web apps (app+node+mongo+redis) ● Fast spin-up VMs (no booting) ● Automated testing and continuous integration/deployment. ● ● Deploying and scaling databases and back-end services in a service-oriented environment. Document what components you need to run your application
  • 4. Why did I seek out Docker ● ● ● Every time a new framework or library was added to our code base the developers got out of sync and we lost productivity We needed a way to synchronize our development environments I also needed a way to keep track of all the components that we were using in our application (i.e. not use history to tell what I have installed)
  • 5. Why not Vagrant ● ● ● Vagrant requires each machine to have VM software like Virtuabox Vagrant is not designed for creating containers for production because of all the overhead Vagrant wasn't any easier to configure than docker, but, the container footprint was larger
  • 6. What  you will need ● A workstation running Linux kernel 3.8 or greater – ● Docker containers can run inside VMs like Virtuabox, but, as Linux containers they are made for Linux Knowledge of how to configure your application on bare hardware – There is lots of help for this
  • 9. Docker speak ● ● ● A container is a running instance of an image. You create an image starting with one of the images found on the index and adding any customizations either from inside the running container or using a Dockerfile Dockerfile-->(build)-->Image---(run)->Container
  • 10. Two work­flows with docker ● Using commits – – Connect to the shell of the base image and add whatever software, customizations and your source (e.g. pull a git remote repository) – Commit to a new image – ● Run a base image Run that image Using Dockerfile – Create a dockerfile that includes all your configurations, customizations and access to your source – This can all be pulled down from git to a different workstation – This is the most reliable option since your Dockerfile should be rewritten that you can recreate the image with one command.
  • 11. How to create a Docker File ● If you don't remember all the packages you installed then you can launch a shell using a base image and then run all the steps. Each step can be copied to the docker file as a “RUN” command
  • 12. Shell for Your Container ● Once a docker image has been created you can run it and enter the bash shell using this command: – sudo docker run -t -i --rm ubuntu bash
  • 13. Docker gotchas ● You can only run one command or entrypoint for a container – – ● ● You only have one cmd or entrypoint. Only one will get executed. You must create a start script or use something like supervisord If you change your source on the client you have to rebuild the image to see those changes on the container. You can't have long running processes in your Dockerfile – Each step is meant to execute and complete – Daemon like functionality should be executed when the container is running
  • 14. Two containers ● ● ● DB container is separate because it rarely changes The Node app resides in its own container Communication is enabled between the two containers using linking – Linking works the same in production environment
  • 15. Example MEAN Stack app ● MongoDB, Express, Angular and Node – Uses PassPortJS for authentication
  • 16. Need to start multiple  processes? ● ● Each Dockerfile will have only one entry point Two options: – Create your own shell script that starts up the processes and call that using a CMD or ENTRYPOINT – Use supervisord
  • 18. Helpful Docker commands  ● logs (sudo docker logs @containerid) – ● Gives a print out of the tty after running ps (sudo docker ps) – – ● Shows you all running containers Containers running in daemon mode will show up here for as long as they are running stop (sudo docker stop @containerid) – Stops a running container
  • 19. Docker Tips ● Only run in daemon mode (-d) if you have run it without -d to see if there are any problems with your configuration – ● You will not see errors printed out to stdout while trying to load the container Watch your disk space while creating images and containers – Docker creates intermediate containers that can quickly eat up disk space – Use the -rm=true when building
  • 20. Questions and Helpful Links ● ● ● ● Main Docker Site: https://docs.docker.io/ Index Site (Prebuilt image search): https://index.docker.io/ How to cleanup docker disk usage: http://sosedoff.com/2013/12/17/cleanup-docker-cont Docker Networking Details: https://blog.codecentric.de/en/2014/01/docker-netwo