Sign inSign up

tplcom/docker-nodejs

By tplcom

•Updated over 10 years ago

Using Docker with NodeJS - presentation

Image
0

1.2K

tplcom/docker-nodejs repository overview

Docker logo

⁠NodeJS.require(Docker)

⁠NodeJS Meetup Thessaloniki⁠, June 2016

⁠TheodorosPloumis.com⁠ / @theoploumis⁠
⁠Get them: online presentation⁠ / source code⁠ / docker image⁠ / video⁠
⁠Share under CC BY 4.0⁠

⁠Let me ask you
  • Who knows about Docker⁠?
  • Who uses Docker for development?
  • Who uses Docker in production?
  • Who tried but could not do it?

⁠What is Docker

Docker is an open platform for developing, shipping, and running applications.

⁠See more on the Docker introduction slides⁠

⁠Docker vs VMs

Docker vs traditional Virtualization


⁠Docker Benefits
  • Fast (deployment, migration, restarts)
  • Secure
  • Lightweight (save disk & CPU)
  • Open Source
  • Portability
  • Microservices and integrations (APIs)
  • Simplify DevOps
  • Version control capabilities
  • Docker: 1-process-per-container && NodeJS: single-process

⁠Technology behind Docker
⁠See more at Understanding docker⁠

⁠Steps of a Docker workflow
docker run -i -t ubuntu /bin/bash

⁠The Docker terminology
  • (docker) engine
  • client
  • machine
  • image
  • container
  • compose
  • swarm
  • distribution

⁠Docker flow diagram

Docker architecture


⁠Agenda
  • Try NodeJS* apps
  • The docker hub
  • Public Dockerfiles
  • Explore docker cli
  • Dockerizing NodeJS
  • Using Docker with NodeJS

⁠Try NodeJS* apps and software
// Try mean.io stack. Open localhost:8010
docker pull gbevan/meanio
docker run -d -p 8010:3000 --name meanio gbevan/meanio

// Try Nagios. Open localhost:8120/nagios (user: nagiosadmin pass: admin)
docker pull quantumobject/docker-nagios
docker run -d -p 8125:25 -p 8120:80 --name nagios quantumobject/docker-nagios

// Try Wekan. Open localhost:8040
docker pull mongo
docker pull mquandalle/wekan
docker run -d --name wekan-db mongo
docker run -d --link "wekan-db:db" \
           -e "MONGO_URL=mongodb://db" -p 8040:80 mquandalle/wekan


⁠The docker hub
⁠Topics: hub, registry, public images

⁠Public Dockerfiles

Popular Dockerfiles from hub.docker.com⁠

Documented Dockerfile reference⁠.

⁠Topics: basics, images, Dockerfile, hub

⁠Explore docker cli commands
// General info
man docker // man docker-run
docker help // docker help run
docker info
docker version
docker network ls

// Images
docker images // docker [IMAGE_NAME]
docker pull [IMAGE] // docker push [IMAGE]

// Containers
docker run ...
docker exec ...
docker ps // docker ps -a, docker ps -l
docker stop/start/restart [CONTAINER_ID]
docker stats [CONTAINER_ID]
docker top [CONTAINER_ID]
docker port [CONTAINER_ID]
docker inspect [CONTAINER_ID]
docker inspect -f "{{ .State.StartedAt }}" [CONTAINER_ID]
docker rm [CONTAINER_ID]

⁠Topics: dry, wharfee, docker simple ui, cli

⁠Dockerizing NodeJS
FROM nodesource/jessie:0.12.13

# Set the NodeJS environment to dev (vs production)
ENV NODE_ENV dev

# cache package.json and node_modules to speed up builds
ADD package.json /package.json
RUN npm install

# Add your local files to the image
ADD . /path/to/app

# Setup the workdir
WORKDIR /path/to/app

# Optional volume the app
VOLUME /path/to/app

# Expose ports
EXPOSE 3000

CMD ["npm","start"]

Other basic examples: 1⁠.

⁠Topics: npm, cache layers

⁠Using Docker with NodeJS

A simple NodeJS app with redis⁠.

git clone [email protected]:thess-docker/docker-scale-node.git
cd docker-scale-node

docker-compose up -d
...

docker-compose run web env
docker-compose logs
docker-compose stop
docker-compose restart
docker-compose down
docker-compose up redis

Other useful examples 1⁠, 2⁠, 3⁠, 4⁠

⁠Topics: docker-compose, ci, testing

⁠Docker tips

There are known best practices (get a list at examples/tips⁠)

  • Optimize containers (check fromlatest.io⁠)
  • Create your own tiny base
  • Containers are not Virtual Machines
  • Full stack Images vs 1 process per Container
  • Create your private registry
  • Create shortcut commands
  • Volume database and code source to save state

⁠Docker NodeJS specific tips
  • Keep the dependencies out of your app (npm_modules)
  • Think of (micro)services and roles
  • Use start scripts for containers with executable
  • Use data only containers and share volumes
  • Keep images small and version-specific
  • In .dockerignore exclude .git, .gitignore, node_modules/
  • Prefer ENTRYPOINT ["npm", "start"]

⁠Docker tools for NodeJS

npm with/for Docker⁠

The Docker ecosystem⁠ grows exponentially.


⁠Instead of Resources

⁠Questions

you.send('Feedback⁠');

NodeJS with Docker!

⁠Tools used: oh my zsh⁠, reveal.js⁠, Simple Docker UI for Chrome⁠, wharfee⁠, dry⁠, docker compose 1.7.1⁠, docker 1.11.1⁠.

⁠Wait, Bonus!

SKGTech.io⁠ has a docker image and a docker-compose.yml file now.

Tag summary

Content type

Image

Digest

Size

295.3 MB

Last updated

over 10 years ago

docker pull tplcom/docker-nodejs