docker

47
Docker Narato DevOps Series

Upload: narato

Post on 18-Jan-2017

134 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Docker

DockerNarato DevOps Series

Page 2: Docker

Agenda

What is docker and why use it The basic docker tools Docker during development Docker during CI and testing Docker in production Q & A

Page 3: Docker

Not on the agenda

How do docker or linux containers actually work

Page 4: Docker

What is Docker?

“Docker allows you to package an application with all of its dependencies into a standardized unit for software development.”

Page 5: Docker

What is Docker?

Docker is an opinioned implementation for building, shipping and deploying applications as standalone containers.

Page 6: Docker

What are docker containers?

Docker containers are a Linux technology!

Page 7: Docker

What are docker containers?

Page 8: Docker

Why?Why would we want to use them?

Page 9: Docker

Why?Languages .NET, NodeJS, Java,

Python. Go, …

ApplicationsWeb Services,

Background Workers, Databases, …

Libraries.NET Framework, ExpressJS, Django, Ruby On Rails, …

Modern architectures have a diverse ecosystem.

More sources to handle.

Page 10: Docker

Why?

Development Environment

Production Environment

Test Environment

IoT Devices Cloud Providers

Virtual Machines

Shared Hosting

CI Environment Linux

Windows OS X QA Environment

Bare Metal

More targets to handle.

Page 11: Docker

Why?

Networking, security, orchestration, oh my …

Page 12: Docker

Virtual Machines vs Docker

Page 13: Docker

The container perspective

Page 14: Docker

Containers

Many products

Page 15: Docker

Containers

Many transports

Page 16: Docker

Linux Containers

Distro and vendor neutral environment for the development of Linux container technologies.LXC, LXD, …

https://linuxcontainers.org/

Page 19: Docker

Docker Tools

Page 20: Docker

Docker Products

Page 21: Docker

docker-machine

Automate Docker provisioning.

Page 22: Docker

docker-machine

docker-machine [command] [machine-name]

docker-machine start default

docker-machine status default

docker-machine env default

Page 23: Docker

docker engine

Docker Engine runs on Linux to create the operating environment for your distributed applications.

Page 24: Docker

docker engine

docker [options] command [arg...]

docker imagesdocker psdocker build .docker run –p “8888:8888” image_name

Page 25: Docker

docker-compose

Docker Compose allows you to define your multi-container application with all of its dependencies in a single file, then spin your application up in a single command.

Page 26: Docker

docker-compose

docker-compose [options] [command] [args]

docker-compose updocker-compose startdocker-compose stopdocker-compose builddocker-compose psdocker-compose scale service=2

Page 27: Docker

swarm

Docker Swarm provides native clustering capabilities to turn a group of Docker engines into a single, virtual Docker Engine.

Page 28: Docker

swarm

Can run as a container on a docker engine instance.

docker run swarm

Page 29: Docker

Using Docker in development

Docker in the development part of Application Lifecycle Management

Page 30: Docker

Development

FROM nodeMAINTAINER Stefan Alaerts <[email protected]>

RUN apt-get update -qq && apt-get install -y build-essential

RUN mkdir /eventhandler-api-serviceCOPY . /eventhandler-api-service/WORKDIR /eventhandler-api-service

ENV NODE_ENV production

RUN npm install

EXPOSE 8888

CMD node lib/index.js

Use a Dockerfile to describe how docker should build an image for your application.

The resulting image should preferably be self-contained.

Page 32: Docker

Development

docker build –t {tag} .

Build images using docker engine.

Page 33: Docker

Development

version: '2'

services:bus: image: rabbitmq:3-management ports: - "15672:15672" - "5672:5672" hostname: eventhandler-bus

api: build: ./src/api ports: - "8888:8888" hostname: eventhandler-api environment: - CONFIGURATION_URL=eventhandler-configuration - CONFIGURATION_PORT=4050 - BUS_URL=eventhandler-bus command: nodemon -L lib/index.js

Use a docker-compose.yml file to describe configuration for multiple containers.

Page 34: Docker

Development

docker-compose up

Use docker-compose to run all of your containers as a single unit.

Page 35: Docker

Tips for Windows usersDon’t suspend your computer while docker-machine is running a machine in VirtualBox.Doing so often breaks networking.

Page 36: Docker

Tips for Windows usersWhen using volumes, make sure your project folder is inside your user home directory. (VirtualBox shared folders limitation.)

Page 37: Docker

Tips for Linux usersUse the power of the command line to remove all images with one command:docker rm `docker ps -aq`

Page 38: Docker

Tips for all usersUse the docker-compose extends functionality.You can auto-reload your application in development by sharing your code using volumes while embedding the code in production.

Most production tools (Docker Cloud, Rancher, …) also support extending compose configurations.

Page 39: Docker

Tips for all usersYou can access the shell of a running container if you need it.

docker exec –i –t [container_id|container_name] bash

Page 40: Docker

Using Docker after development

Docker in the CI and testing part of Application Lifecycle Management

Page 41: Docker

Extending development flow

Docker Machine (Windows, OSX)Docker EngineDocker Compose

Page 42: Docker

Application Lifecycle Management

https://blog.docker.com/2015/09/docker-hub-2-0/

Page 43: Docker

DevOps with Docker

http://thenewstack.io/how-docker-fits-into-the-devops-ecosystem/

Page 44: Docker

DevOps with Docker

https://dzone.com/articles/docker-hub-20-integration-with-the-cloudbees-jenki

Page 45: Docker

Tools for production

Docker Cloud (previously Tutum) Rancher Deis

http://deis.io/ Atomic

http://www.projectatomic.io/

Page 46: Docker

Example: deploying a NodeJS blog

docker login --username=salaerts [email protected] docker build –t salaerts/blog . docker push salaerts/blog

Page 47: Docker

Example: deploying a NodeJS blog

git push origin master Docker Hub kicks off an automated build on each push