{"user":"tplcom","name":"docker-nodejs","namespace":"tplcom","repository_type":null,"status":1,"status_description":"active","description":"Using Docker with NodeJS - presentation","is_private":false,"is_automated":true,"star_count":0,"pull_count":371,"last_updated":"2016-06-09T13:01:30.830243Z","last_modified":"2024-10-16T13:48:34.145251Z","date_registered":"2016-06-07T22:35:12.061021Z","collaborator_count":0,"affiliation":null,"hub_user":"tplcom","has_starred":false,"full_description":"![Docker logo](https://raw.githubusercontent.com/theodorosploumis/docker-nodejs/gh-pages/img/docker_logo.png)\n\n## NodeJS.require(Docker)\n\n#### [NodeJS Meetup Thessaloniki](http://www.meetup.com/Thessaloniki-Node-js-Meetup/events/231574221/), June 2016\n\n_________________\n\n###### [TheodorosPloumis.com](http://www.theodorosploumis.com/en) / [@theoploumis](twitter.com/theoploumis)\n\n###### Get them: [online presentation](http://theodorosploumis.github.io/docker-nodejs/) / [source code](https://github.com/theodorosploumis/docker-nodejs) / [docker image](https://hub.docker.com/r/tplcom/docker-nodejs/) / [video](https://www.youtube.com/watch?v=ALEE6oTUQOE)\n\n###### Share under [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/)\n\n---\n\n### Let me ask you\n\n- Who knows about [Docker](http://docker.com)?\n- Who uses Docker for development?\n- Who uses Docker in production?\n- Who tried but could not do it?\n\n---\n\n### What is Docker\n\n\u003e Docker is an open platform for developing, shipping, and running applications.\n\n###### See more on the [Docker introduction slides](http://theodorosploumis.github.io/docker-presentation/)\n\n---\n\n### Docker vs VMs\n\n![Docker vs traditional Virtualization](https://insights.sei.cmu.edu/assets/content/VM-Diagram.png)\n\n---\n\n### Docker Benefits\n\n- Fast (deployment, migration, restarts)\n- Secure\n- Lightweight (save disk \u0026 CPU)\n- Open Source\n- Portability\n- Microservices and integrations (APIs)\n- Simplify DevOps\n- Version control capabilities\n- Docker: 1-process-per-container \u0026\u0026 NodeJS: single-process\n\n---\n\n### Technology behind Docker\n\n- Linux [x86-64](https://www.wikiwand.com/en/X86-64)\n- [Go](https://golang.org/) language\n- [Client- Server](https://www.wikiwand.com/en/Client%E2%80%93server_model) (deamon) architecture\n- Union file systems ([UnionFS](https://www.wikiwand.com/en/UnionFS): AUFS, btrfs, vfs etc)\n- [Namespaces](https://en.wikipedia.org/wiki/Cgroups#NAMESPACE-ISOLATION) (pid, net, ipc, mnt, uts)\n- Control Groups ([cgroups](https://www.wikiwand.com/en/Cgroups))\n- Container format ([libcontainer](https://github.com/opencontainers/runc/tree/master/libcontainer \"Libcontainer provides a native Go implementation for creating containers with namespaces, cgroups, capabilities, and filesystem access controls. It allows you to manage the lifecycle of the container performing additional operations after the container is created.\"))\n\n###### See more at [Understanding docker](https://docs.docker.com/engine/understanding-docker/)\n\n---\n\n### Steps of a Docker workflow\n\n```\ndocker run -i -t ubuntu /bin/bash\n```\n\n- Pulls the ubuntu [image](https://docs.docker.com/engine/userguide/containers/dockerimages/ \"A read-only layer that is the base of your container. It can have a parent image to abstract away the more basic filesystem snapshot.\") from the [registry](https://docs.docker.com/registry/ \"The central place where all publicly published images live. You can search it, upload your images there and when you pull a docker image, it comes the repository/hub.\")\n- Creates a new [CONTAINER_ID](https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/ \"A runnable instance of the image, basically it is a process isolated by docker that runs on top of the filesystem that an image provides.\")\n- Allocates a filesystem and mounts a read-write [layer](https://docs.docker.com/engine/reference/glossary/#filesystem \"A set of read-only files to provision the system. Think of a layer as a read only snapshot of the filesystem.\")\n- Allocates a [network/bridge interface](https://www.wikiwand.com/en/Bridging_%28networking%29 \"\")\n- Sets up an [IP address](https://www.wikiwand.com/en/IP_address \"An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication.\")\n- Executes a process that you specify (``` /bin/bash ```)\n- Captures and provides application output\n\n---\n\n### The Docker terminology\n\n- (docker) engine\n- client\n- machine\n- image\n- container\n- compose\n- swarm\n- distribution\n\n---\n\n### Docker flow diagram\n\n![Docker architecture](https://docs.docker.com/engine/article-img/architecture.svg)\n\n---\n\n### Agenda\n\n- Try NodeJS* apps\n- The docker hub\n- Public Dockerfiles\n- Explore docker cli\n- Dockerizing NodeJS\n- Using Docker with NodeJS\n\n---\n\n### Try NodeJS* apps and software\n\n```\n// Try mean.io stack. Open localhost:8010\ndocker pull gbevan/meanio\ndocker run -d -p 8010:3000 --name meanio gbevan/meanio\n\n// Try Nagios. Open localhost:8120/nagios (user: nagiosadmin pass: admin)\ndocker pull quantumobject/docker-nagios\ndocker run -d -p 8125:25 -p 8120:80 --name nagios quantumobject/docker-nagios\n\n// Try Wekan. Open localhost:8040\ndocker pull mongo\ndocker pull mquandalle/wekan\ndocker run -d --name wekan-db mongo\ndocker run -d --link \"wekan-db:db\" \\\n           -e \"MONGO_URL=mongodb://db\" -p 8040:80 mquandalle/wekan\n\n```\n###### Topics: run, link, ports, containers\n\n---\n\n### The docker hub\n\n- [hub.docker.com](https://hub.docker.com/)\n- [page of readytalk/nodejs](https://hub.docker.com/r/readytalk/nodejs/)\n- [REST API v1](https://docs.docker.com/v1.6/reference/api/docker-io_api/)\n- [REST API v2](https://docs.docker.com/registry/spec/api/)\n- [images of readytalk/nodejs, v1](https://registry.hub.docker.com/v1/repositories/readytalk/nodejs/images)\n- [info about tplcom namespace. v2](https://registry.hub.docker.com/v2/repositories/tplcom/docker-nodejs/)\n- Let's upload [theodorosploumis/php-chat](https://github.com/theodorosploumis/php-chat) to the hub\n\n###### Topics: hub, registry, public images\n\n---\n\n### Public Dockerfiles\n\nPopular Dockerfiles from [hub.docker.com](https://hub.docker.com)\n\n- A list of [NodeJS](https://hub.docker.com/search/?page=1\u0026q=nodejs\u0026starCount=0) public images\n- [node/0.10.45](https://github.com/nodejs/docker-node/blob/5e058d36cc69303d1f62d424615fa03e050f20ef/0.10/Dockerfile)\n- [node/slim](https://hub.docker.com/r/library/node/tags/slim/)\n- [jprjr/tinynode](https://hub.docker.com/r/jprjr/tinynode/)\n- [shawnzhu/ruby-nodejs](https://hub.docker.com/r/shawnzhu/ruby-nodejs/)\n- [scratch](https://hub.docker.com/_/scratch/)\n- [nodesource explicit images](https://github.com/nodesource/docker-node#usage)\n\nDocumented [Dockerfile reference](https://github.com/theodorosploumis/docker-presentation/blob/gh-pages/examples/dockerfile/Dockerfile).\n\n###### Topics: basics, images, Dockerfile, hub\n\n---\n\n### Explore docker cli commands\n\n```\n// General info\nman docker // man docker-run\ndocker help // docker help run\ndocker info\ndocker version\ndocker network ls\n\n// Images\ndocker images // docker [IMAGE_NAME]\ndocker pull [IMAGE] // docker push [IMAGE]\n\n// Containers\ndocker run ...\ndocker exec ...\ndocker ps // docker ps -a, docker ps -l\ndocker stop/start/restart [CONTAINER_ID]\ndocker stats [CONTAINER_ID]\ndocker top [CONTAINER_ID]\ndocker port [CONTAINER_ID]\ndocker inspect [CONTAINER_ID]\ndocker inspect -f \"{{ .State.StartedAt }}\" [CONTAINER_ID]\ndocker rm [CONTAINER_ID]\n\n```\n\n###### Topics: dry, wharfee, docker simple ui, cli\n\n---\n\n### Dockerizing NodeJS\n\n```\nFROM nodesource/jessie:0.12.13\n\n# Set the NodeJS environment to dev (vs production)\nENV NODE_ENV dev\n\n# cache package.json and node_modules to speed up builds\nADD package.json /package.json\nRUN npm install\n\n# Add your local files to the image\nADD . /path/to/app\n\n# Setup the workdir\nWORKDIR /path/to/app\n\n# Optional volume the app\nVOLUME /path/to/app\n\n# Expose ports\nEXPOSE 3000\n\nCMD [\"npm\",\"start\"]\n```\n\nOther basic examples: [1](https://docs.docker.com/engine/examples/nodejs_web_app/).\n\n###### Topics: npm, cache layers\n\n---\n\n### Using Docker with NodeJS\n\nA simple [NodeJS app with redis](https://github.com/thess-docker/docker-scale-node/).\n\n```\ngit clone git@github.com:thess-docker/docker-scale-node.git\ncd docker-scale-node\n\ndocker-compose up -d\n...\n\ndocker-compose run web env\ndocker-compose logs\ndocker-compose stop\ndocker-compose restart\ndocker-compose down\ndocker-compose up redis\n\n```\n\nOther useful examples [1](https://github.com/thess-docker/example-voting-app), [2](https://github.com/thess-docker/docker-compose-nodejs), [3](https://github.com/thess-docker/nodejs-loadbalanced-dockercompose), [4](https://github.com/thess-docker/docker-nodejs-postgres)\n\n###### Topics: docker-compose, ci, testing\n\n---\n\n### Docker tips\n\nThere are known best practices (get a list at [examples/tips](https://github.com/theodorosploumis/docker-presentation/tree/gh-pages/examples/tips))\n\n- Optimize containers (check [fromlatest.io](https://www.fromlatest.io/))\n- Create your own tiny base\n- Containers are not Virtual Machines\n- Full stack Images vs 1 process per Container\n- Create your private registry\n- Create shortcut commands\n- Volume database and code source to save state\n\n---\n\n### Docker NodeJS specific tips\n\n- Keep the dependencies out of your app (npm_modules)\n- Think of (micro)services and roles\n- Use start scripts for containers with executable\n- Use data only containers and share volumes\n- Keep images small and version-specific\n- In .dockerignore exclude ```.git, .gitignore, node_modules/```\n- Prefer ```ENTRYPOINT [\"npm\", \"start\"]```\n\n---\n\n### Docker tools for NodeJS\n\n[npm with/for Docker](https://www.npmjs.com/search?q=docker)\n\n- [dockerode](https://www.npmjs.com/package/dockerode)\n- [dockunit](https://www.npmjs.com/package/dockunit)\n- [docker node tester, dnt](https://www.npmjs.com/package/dnt)\n- [generator-docker](https://www.npmjs.com/package/generator-docker)\n\nThe [Docker ecosystem](http://comp.photo777.org/wp-content/uploads/2015/09/Docker-ecosystem-8.5.1.pdf) grows exponentially.\n\n---\n\n### Instead of Resources\n\n- Join [beta.docker.com](https://beta.docker.com/) now!\n- Subscribe to the official [Newsletter](https://www.docker.com/newsletter-subscription)\n- [Awesome Docker](https://github.com/veggiemonk/awesome-docker) (list of Docker resources \u0026 projects)\n- [Docker cheat sheet](https://github.com/wsargent/docker-cheat-sheet)\n- [Docker in Practice](https://www.manning.com/books/docker-in-practice), [The Docker Book](http://www.dockerbook.com/) (books)\n- [Docker aliases/shortcuts](https://github.com/theodorosploumis/docker-presentation/tree/gh-pages/examples/shortcuts/docker-aliases.sh)\n- [Docker introduction presentation](http://theodorosploumis.github.io/docker-presentation/)\n\n---\n\n### Questions\n\nyou.send('[Feedback](https://goo.gl/T7rE1o)');\n\n![NodeJS with Docker!](https://raw.githubusercontent.com/theodorosploumis/docker-nodejs/gh-pages/img/docker_nodejs.png)\n\n###### Tools used: [oh my zsh](http://ohmyz.sh/), [reveal.js](https://github.com/hakimel/reveal.js), [Simple Docker UI for Chrome](https://github.com/felixgborrego/docker-ui-chrome-app), [wharfee](https://github.com/j-bennet/wharfee), [dry](https://github.com/moncho/dry), [docker compose 1.7.1](https://github.com/docker/compose/releases/tag/1.7.1), [docker 1.11.1](https://github.com/docker/docker/releases/tag/v1.11.1).\n\n---\n\n### Wait, Bonus!\n\n\u003e [SKGTech.io](http://skgtech.io) has a docker image and a **docker-compose.yml** file now.\n","permissions":{"read":true,"write":false,"admin":false},"media_types":["application/vnd.docker.container.image.v1+json"],"content_types":["image"],"categories":[],"immutable_tags_settings":{"enabled":false,"rules":[".*"]},"storage_size":666200526,"source":null}