NodeJS Meetup Thessaloniki, June 2016
Get them: online presentation / source code / docker image / video
Share under CC BY 4.0
- Who knows about Docker?
- Who uses Docker for development?
- Who uses Docker in production?
- Who tried but could not do it?
Docker is an open platform for developing, shipping, and running applications.
See more on the Docker introduction slides
- 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
- Linux x86-64
- Go language
- Client- Server (deamon) architecture
- Union file systems (UnionFS: AUFS, btrfs, vfs etc)
- Namespaces (pid, net, ipc, mnt, uts)
- Control Groups (cgroups)
- Container format (libcontainer)
See more at Understanding docker
docker run -i -t ubuntu /bin/bash
- Pulls the ubuntu image from the registry
- Creates a new CONTAINER_ID
- Allocates a filesystem and mounts a read-write layer
- Allocates a network/bridge interface
- Sets up an IP address
- Executes a process that you specify (
/bin/bash
) - Captures and provides application output
- (docker) engine
- client
- machine
- image
- container
- compose
- swarm
- distribution
- Try NodeJS* apps
- The docker hub
- Public Dockerfiles
- Explore docker cli
- Dockerizing NodeJS
- Using Docker with NodeJS
// 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
- hub.docker.com
- page of readytalk/nodejs
- REST API v1
- REST API v2
- images of readytalk/nodejs, v1
- info about tplcom namespace. v2
- Let's upload theodorosploumis/php-chat to the hub
Popular Dockerfiles from hub.docker.com
- A list of NodeJS public images
- node/0.10.45
- node/slim
- jprjr/tinynode
- shawnzhu/ruby-nodejs
- scratch
- nodesource explicit images
Documented Dockerfile reference.
// 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]
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.
A simple NodeJS app with redis.
git clone git@github.com: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
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
- 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"]
The Docker ecosystem grows exponentially.
- Join beta.docker.com now!
- Subscribe to the official Newsletter
- Awesome Docker (list of Docker resources & projects)
- Docker cheat sheet
- Docker in Practice, The Docker Book (books)
- Docker aliases/shortcuts
- Docker introduction presentation
you.send('Feedback');
Tools used: oh my zsh, reveal.js, Simple Docker UI for Chrome, wharfee, dry, docker compose 1.7.1, docker 1.11.1.
SKGTech.io has a docker image and a docker-compose.yml file now.