12 factor app with docker
TRANSCRIPT
12-Factor App with Docker
Ophélie Mauger Consultante DevOps - Alter Way
Why twelve-factor app ?● Maximum portability between environments
● Suitable for deployment on modern cloud platforms
● Scale up
● Minimize time and costs with automation
● Continuous deployment
Why docker can help ?● Maximum portability between environments
● Suitable for deployment on modern cloud platforms
● Scale up
● Minimize time and costs with automation
● Continuous deployment
12 factor App with docker step by step
codebase dependencies config backing services
build, release, runprocesses
port binding concurrency
disposability dev/prod parity Logs
Admin processes
I. CodeBase
One codebase tracked in revision control
II. Dependencies
Explicitly declare & isolate dependencies
|||. Config
Store config in the environment
● Linux environment variables
● docker-compose can define env variables via env files
IV. Backing services
Treat backing services as attached
ressources
● Linux environment variables
● docker-compose can define env variables via env files
● docker allows you to link services together
V. Build, Release, Run
Strictly separate build and run stages
● docker build --pull -t sampleapi:1.0 .
● docker push sampleapi:1.0
● docker run sampleapi:1.0
VI. Processes
Execute the app as one or more stateless
processes
● docker enforces stateless processes
● Use volumes to persist data
Export services via port binding
VII. Port Binding
Docker Host
service network
container http
container php-fpm
container mysql
port binding
VIII. Concurrency
Scale out via the process model
Docker Cluster
docker host docker host docker host
http php
worker worker
worker worker
http php
worker worker
worker worker
http php
worker worker
worker worker
Workload divercity
scale
IX. Disposability
Maximize robustness with fast startup and
graceful shutdown
● Container restart policies
● Orchestration with docker swarm
● Reverse proxy and load balancing with
services containers
X. Dev/Prod parity
Keep development, staging, and
production as similar as possible
● “build once, run anywhere”
● Same app images across DevOps stages
XI. Logs
Treat logs as event streams
Dev environment
Logs in container stdout
>docker logs -f …>docker-compose logs -f
Ops environment
Log driver : fluentd
container fluentd
XII. Admin processes
Run Admin/management tasks as one of
processes
docker exec ….
And what about continuous deployment ?
Continuous Delivery with DockerBuild stage :
● docker build --pull -t myregistry/myimage:$version
● docker push myregistry/myimage:$version
Continuous Deployment with dockerDeploy stage :
● Connect to the swarm (export DOCKER_HOST, ...)
● docker-compose pull
● docker-compose up -d
ConclusionIf you plan to do a twelve-factor app
use docker to make it