Top Banner
DOCKER INTRODUCTION TO CONTAINERS FOR PHP DEVELOPERS
81

Docker - introduction

Apr 15, 2017

Download

Software

Michał Kurzeja
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Docker - introduction

DOCKERINTRODUCTION TO CONTAINERS FOR PHP DEVELOPERS

Page 2: Docker - introduction

DOCKER - INTRODUCTION FOR PHP DEVELOPERS

MICHAŁ KURZEJA

▸ CTO at accesto.com

[email protected]

▸ @michalKurzeja

▸ Homebrewer

▸ Swimmer/runner

Page 3: Docker - introduction
Page 4: Docker - introduction

WHY DOCKER?

Page 5: Docker - introduction
Page 6: Docker - introduction

DOCKER

SYSTEM DEPENDENCIES

Page 7: Docker - introduction

DOCKER

SYSTEM DEPENDENCIES

PROJECT 1

PROJECT 2

PROJECT 3* M

Page 8: Docker - introduction

DOCKER

SYSTEM DEPENDENCIES

Developer 1

Tester

Developer 2

CIStaging

* N

Page 9: Docker - introduction

DOCKER - INTRODUCTION FOR PHP DEVELOPERS

PROJECT DEPENDENCY MATRIX FROM HELL

Dev Stage Prod CI

PHP ? ? ? ?

MySQL ? ? ? ?

Redis ? ? ? ?RabbitMQ ? ? ? ?Neo4j ? ? ? ?

Hadoop/Spark ? ? ? ?

Page 10: Docker - introduction

DOCKER - INTRODUCTION FOR PHP DEVELOPERS

PROJECT DEPENDENCY MATRIX FROM HELL

Dev Stage Prod CI

PHP ? ?

MySQL ? ? ?

Redis ? ? ? ?RabbitMQ ? ? ? ?Neo4j ? ? ? ?

Hadoop/Spark ? ? ? ?

Page 11: Docker - introduction

PROFITS?

Page 12: Docker - introduction

BUILD ONCE, EXECUTE EVERYWHERE*

Page 13: Docker - introduction

NO DEPENDENCY & NO INCOMPATIBILITY ISSUES

Page 14: Docker - introduction

VM WITHOUT OVERHEAD

Page 15: Docker - introduction

FULLY AUTOMATED

Page 16: Docker - introduction

EASY TO DEPLOY

Page 17: Docker - introduction

SEPARATION OF DUTIES

Page 18: Docker - introduction

SCALABILITY

Page 19: Docker - introduction

TECHNICAL BACKGROUND

Page 20: Docker - introduction

TEKST

VIRTUAL MACHINES VS CONTAINERS

Page 21: Docker - introduction

TEKST

WHY IS DOCKER FAST?

Page 22: Docker - introduction

IMAGE

Page 23: Docker - introduction

IMAGE LAYER

Page 24: Docker - introduction

imagelayers.io

Page 25: Docker - introduction

CONTAINER

Page 26: Docker - introduction

REPOSITORY

Page 27: Docker - introduction

DOCKER HUB

Page 28: Docker - introduction

DEMO TIME!

Page 29: Docker - introduction

docker run docker/whalesay cowsay PHP!

Page 30: Docker - introduction

docker run docker/whalesay cowsay PHP!

Page 31: Docker - introduction

docker run docker/whalesay cowsay PHP!

Page 32: Docker - introduction

docker run docker/whalesay cowsay PHP!

Page 33: Docker - introduction
Page 34: Docker - introduction

docker run -v $PWD:/var/www/html -p 8081:80 php:5.6-apache

Page 35: Docker - introduction

docker run -v $PWD:/var/www/html -p 8081:80 php:5.6-apache

Page 36: Docker - introduction

docker run -v $PWD:/var/www/html -p 8081:80 php:5.6-apache 7.0-apache

Page 37: Docker - introduction
Page 38: Docker - introduction
Page 39: Docker - introduction

READY TO DIVE DEEPER?

Page 40: Docker - introduction

OWN DOCKER IMAGE

Page 41: Docker - introduction

FROM docker/whalesay:latest

Dockerfile

Page 42: Docker - introduction

FROM docker/whalesay:latestRUN apt-get -y update && apt-get install -y fortunes

Dockerfile

Page 43: Docker - introduction

FROM docker/whalesay:latestRUN apt-get -y update && apt-get install -y fortunesCMD /usr/games/fortune -a | cowsay

Dockerfile

Page 44: Docker - introduction

FROM docker/whalesay:latestRUN apt-get -y update && apt-get install -y fortunesCMD /usr/games/fortune -a | cowsay

docker build -t docker-whale .

Dockerfile

Page 45: Docker - introduction

FROM docker/whalesay:latestRUN apt-get -y update && apt-get install -y fortunesCMD /usr/games/fortune -a | cowsay

docker build -t docker-whale .

Dockerfile

Page 46: Docker - introduction

FROM docker/whalesay:latestRUN apt-get -y update && apt-get install -y fortunesCMD /usr/games/fortune -a | cowsay

docker build -t docker-whale .docker run docker-whale

Dockerfile

Page 47: Docker - introduction
Page 48: Docker - introduction
Page 49: Docker - introduction
Page 50: Docker - introduction
Page 51: Docker - introduction

EVERYTHING IN ONE CONTAINER ?

Page 52: Docker - introduction

MULTIPLE CONTAINERS!

Page 53: Docker - introduction

DOCKER COMPOSE

Page 54: Docker - introduction

docker run -v $PWD/www:/var/www/html -p 8081:80 php:7.0-apache

Page 55: Docker - introduction

docker run -v $PWD/www:/var/www/html -p 8081:80 php:7.0-apacheX

Page 56: Docker - introduction

#docker-compose.yml

www: image: php:7.0-apache

docker run -v $PWD/www:/var/www/html -p 8081:80 php:7.0-apache

Page 57: Docker - introduction

#docker-compose.yml

www: image: php:7.0-apache volumes: - ./www:/var/www/html

docker run -v $PWD/www:/var/www/html -p 8081:80 php:7.0-apache

Page 58: Docker - introduction

#docker-compose.yml

www: image: php:7.0-apache volumes: - ./www:/var/www/html ports: - 8081:80

docker run -v $PWD/www:/var/www/html -p 8081:80 php:7.0-apache

Page 59: Docker - introduction

#docker-compose.yml

www: image: php:7.0-apache volumes: - ./www:/var/www/html ports: - 8081:80

docker-compose up

Page 60: Docker - introduction
Page 61: Docker - introduction

LINKING CONTAINERS

Page 62: Docker - introduction

WWW REDIS

Page 63: Docker - introduction

www: image: php:7.0-apache volumes: - ./www:/var/www/html ports: - 8081:80 redis: image: redis

Page 64: Docker - introduction

www: image: php:7.0-apache volumes: - ./www:/var/www/html ports: - 8081:80 links: - redis redis: image: redis

Page 65: Docker - introduction

<?php

/* www/index.php */

require_once __DIR__.'/vendor/autoload.php';

$client = new Predis\Client(['host' => 'redis']);

$counter = $client->incr('counter');

echo "Hostname: ".gethostname().PHP_EOL;

echo " Counter: ".$counter.PHP_EOL;

Page 66: Docker - introduction

docker-compose ps

Page 67: Docker - introduction

SCALING APPLICATIONS

Page 68: Docker - introduction

WWW REDIS

WWW

WWW

HAPROXY

Page 69: Docker - introduction

version: '2'services: www: image: php:7.0-apache volumes: - ./www:/var/www/html ports: - 8081:80 links: - redis redis: image: redis

Page 70: Docker - introduction

version: '2'services: www: … haproxy: image: 'dockercloud/haproxy:latest' redis: …

Page 71: Docker - introduction

version: '2'services: www: … haproxy: image: 'dockercloud/haproxy:latest' links: - www redis: …

Page 72: Docker - introduction

version: '2'services: www: … haproxy: image: 'dockercloud/haproxy:latest' links: - www ports: - '80:80' redis: …

Page 73: Docker - introduction

version: '2'services: www: … haproxy: image: 'dockercloud/haproxy:latest' links: - www ports: - '80:80' environment: - DOCKER_TLS_VERIFY - DOCKER_HOST - DOCKER_CERT_PATH volumes: - $DOCKER_CERT_PATH:$DOCKER_CERT_PATH redis: …

Page 74: Docker - introduction

docker-compose up -d

docker-compose scale www=3

docker-compose ps

Page 75: Docker - introduction
Page 76: Docker - introduction

DEEPER?

Page 77: Docker - introduction

DOCKER SWARM

MESOSPHERE

KUBERNETES

Page 78: Docker - introduction

DOCKER

PACKAGING OWN APPLICATIONS

▸ Use Dockerfile

▸ COPY project code

▸ Orchestrate [with compose]

▸ Split into multiple containers

Page 79: Docker - introduction

DOCKER

DEPLOYMENT TIPS&TRICKS

▸ Own in-house docker repository

▸ No direct disk usage

▸ Gaufrette - filesystem abstraction

▸ Logstash - logs

▸ Session in redis/memcached

Page 80: Docker - introduction

CHALLENGE ACCEPTED?

Page 81: Docker - introduction

QUESTIONS?