beginners guide to kontena

28
Beginners Guide to Kontena Lauri Nevala, Founder

Upload: kontena-inc

Post on 12-Jan-2017

504 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Beginners Guide To Kontena

Beginners Guide to KontenaLauri Nevala, Founder

Page 2: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Docker Basics• Docker is an open source project to • pack, • ship• run

any application as a lightweight container

Page 3: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Pack

Page 4: Beginners Guide To Kontena

© 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

Page 5: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Ship

Page 6: Beginners Guide To Kontena

© 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

Page 7: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Run

Page 8: Beginners Guide To Kontena

© 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

Page 9: Beginners Guide To Kontena

Example

Page 10: Beginners Guide To Kontena

Node.js Docker Application• package.json• index.js• Dockerfile

Page 11: Beginners Guide To Kontena

© 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" }}

Page 12: Beginners Guide To Kontena

© 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);

Page 13: Beginners Guide To Kontena

© 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" ]

Page 14: Beginners Guide To Kontena

© 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

Page 15: Beginners Guide To Kontena

© 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

Page 16: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Test$ curl http://<docker_host_ip>:49160

Page 17: Beginners Guide To Kontena

© 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?• ???

Page 18: Beginners Guide To Kontena

© 2015 Kontena, Inc.

“I don’t want to think all that, I just want to develop my killer

app!”

Page 19: Beginners Guide To Kontena

The Docker Platform

Page 20: Beginners Guide To Kontena

© 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

Page 21: Beginners Guide To Kontena

© 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

Page 22: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Monitoring Applications• $ kontena app monitor• $ kontena app logs• $ kontena service stats

Page 23: Beginners Guide To Kontena

© 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

Page 24: Beginners Guide To Kontena

© 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

Page 25: Beginners Guide To Kontena

© 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

Page 26: Beginners Guide To Kontena

© 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

Page 27: Beginners Guide To Kontena

© 2015 Kontena, Inc.

Page 28: Beginners Guide To Kontena

Thank You!www.kontena.io