beginners guide to kontena
TRANSCRIPT
Beginners Guide to KontenaLauri Nevala, Founder
© 2015 Kontena, Inc.
Docker Basics• Docker is an open source project to • pack, • ship• run
any application as a lightweight container
© 2015 Kontena, Inc.
Pack
© 2015 Kontena, Inc.
Dockerfile• Dockerfile is a text document that contains all the
commands a user could call on the command line to assemble an image
© 2015 Kontena, Inc.
Ship
© 2015 Kontena, Inc.
Docker Image• docker build command builds an image from a Dockerfile and a context. • The build’s context is the files at a specified location
PATH or URL.• Docker images can be stored in registry services• Docker Hub• Docker Registry
© 2015 Kontena, Inc.
Run
© 2015 Kontena, Inc.
Docker Run• Running an application inside a container takes a single
command: docker run. • $ docker run ubuntu:14.04 /bin/echo ‘Hello world’• First we specified the docker binary and the command we
wanted to execute, run• Next we specified an image: ubuntu:14.04. This is the source
of the container we ran. • Next we told Docker what command to run inside our new
container
Example
Node.js Docker Application• package.json• index.js• Dockerfile
© 2015 Kontena, Inc.
Package.json{ "name": "docker_web_app", "version": "1.0.0", "description": "Node.js on Docker", "author": “Lauri Nevala <[email protected]>", "main": "index.js", "dependencies": { "express": "^4.13.3” } "scripts": { "start": "node index.js" }}
© 2015 Kontena, Inc.
Index.js'use strict'; const express = require('express');
// Constants const PORT = 8080;
// Appconst app = express(); app.get('/', function (req, res) { res.send('Hello world\n');});
app.listen(PORT);console.log('Running on http://localhost:' + PORT);
© 2015 Kontena, Inc.
DockerfileFROM node:argon
# Create app directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Install app dependencies COPY package.json /usr/src/app/ RUN npm install
# Bundle app source COPY . /usr/src/app
EXPOSE 8080 CMD [ "npm", "start" ]
© 2015 Kontena, Inc.
Building the Image$ docker build -t <your username>/node-web-app .
• The -t flag lets you tag your image so it's easier to find later using the docker images command
© 2015 Kontena, Inc.
Run the Image$ docker run –d -p 49160:8080 –name node-web-app <your username>/node-web-app
• Running the image with -d runs the container in detached mode, leaving the container running in the background. • The -p flag redirects a public port to a private port inside the
container.• The –name flag lets you name your image so it's easier to find
it later.• Image is first searched from local registry then from Docker
Hub
© 2015 Kontena, Inc.
Test$ curl http://<docker_host_ip>:49160
© 2015 Kontena, Inc.
Application Considerations• Where to store images?
• Public hub• Private registry
• How to setup?• How to run applications on production environment?
• Deploying applications: how? who?• Microservices and networking• Multi-node environments: different availability zones, different cloud
providers• High-Availability applications
• How to monitor applications?• ???
© 2015 Kontena, Inc.
“I don’t want to think all that, I just want to develop my killer
app!”
The Docker Platform
© 2015 Kontena, Inc.
Deploying Application with Kontena1. Setup Kontena• http://www.kontena.io/docs/getting-started/quick-start
2. Create Kontena service$ kontena service create -p 49160:8080 node-web-app nevalla/node-web-app:latest
3. Deploy service$ kontena service deploy node-web-app
© 2015 Kontena, Inc.
Familiar with Docker-compose?// kontena.ymlnode-web-app: image: registry.kontena.local/node-web-app:latest ports: - 80:8080
$ kontena app deploy
© 2015 Kontena, Inc.
Monitoring Applications• $ kontena app monitor• $ kontena app logs• $ kontena service stats
© 2015 Kontena, Inc.
Scaling Applications// kontena.ymlnode-web-app: image: registry.kontena.local/node-web-app:latest instances: 2 ports: - 80:8080
$ kontena app scale node-web-app 2
© 2015 Kontena, Inc.
Stateful Services• Services with persistent data (databases etc)• Data won’t be lost between deploys
// kontena.ymlredis: image: redis:latest stateful: true
// containersredis-1 volumes_from: redis-1-volumesredis-1-volumes
© 2015 Kontena, Inc.
Linking Services// kontena.ymlwordpress: image: wordpress:4.1 stateful: true ports: - 8080:80 links: - mysql:wordpress-mysql environment: - WORDPRESS_DB_HOST=%{project}-mysql.kontena.local env_file: wordpress.env
mysql: image: mariadb:5.5 stateful: true environment: - MYSQL_ROOT_PASSWORD=secret
© 2015 Kontena, Inc.
More complex exampleMongoDB cluster
mongo: image: mongo:3.0 stateful: true command: --replSet kontena --smallfiles instances: 3 hooks: post_start: - cmd: sleep 10 name: sleep instances: 1 oneshot: true - cmd: mongo --eval "printjson(rs.initiate());" name: rs_initiate instances: 1 oneshot: true - cmd: mongo --eval "printjson(rs.add('meetup-mongo-2'))" name: rs_add2 instances: 1 oneshot: true - cmd: mongo --eval "printjson(rs.add('meetup-mongo-3'))" name: rs_add3 instances: 1 oneshot: true
© 2015 Kontena, Inc.
Thank You!www.kontena.io