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, run
processes
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 Docker
Build stage :
● docker build --pull -t myregistry/myimage:$version
● docker push myregistry/myimage:$version
Continuous Deployment with docker
Deploy stage :
● Connect to the swarm (export DOCKER_HOST, ...)
● docker-compose pull
● docker-compose up -d
Conclusion
If you plan to do a twelve-factor app
use docker to make it

12 FACTOR APP WITH DOCKER

  • 1.
    12-Factor App withDocker Ophélie Mauger Consultante DevOps - Alter Way
  • 2.
    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
  • 3.
    Why docker canhelp ? ● Maximum portability between environments ● Suitable for deployment on modern cloud platforms ● Scale up ● Minimize time and costs with automation ● Continuous deployment
  • 4.
    12 factor Appwith docker step by step codebase dependencies config backing services build, release, run processes port binding concurrency disposability dev/prod parity Logs Admin processes
  • 5.
    I. CodeBase One codebasetracked in revision control
  • 6.
  • 7.
    |||. Config Store configin the environment ● Linux environment variables ● docker-compose can define env variables via env files
  • 8.
    IV. Backing services Treatbacking services as attached ressources ● Linux environment variables ● docker-compose can define env variables via env files ● docker allows you to link services together
  • 9.
    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
  • 10.
    VI. Processes Execute theapp as one or more stateless processes ● docker enforces stateless processes ● Use volumes to persist data
  • 11.
    Export services viaport binding VII. Port Binding Docker Host service network container http container php-fpm container mysql port binding
  • 12.
    VIII. Concurrency Scale outvia 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
  • 13.
    IX. Disposability Maximize robustnesswith fast startup and graceful shutdown ● Container restart policies ● Orchestration with docker swarm ● Reverse proxy and load balancing with services containers
  • 14.
    X. Dev/Prod parity Keepdevelopment, staging, and production as similar as possible ● “build once, run anywhere” ● Same app images across DevOps stages
  • 15.
    XI. Logs Treat logsas event streams Dev environment Logs in container stdout >docker logs -f … >docker-compose logs -f Ops environment Log driver : fluentd container fluentd
  • 16.
    XII. Admin processes RunAdmin/management tasks as one of processes docker exec ….
  • 17.
  • 18.
    Continuous Delivery withDocker Build stage : ● docker build --pull -t myregistry/myimage:$version ● docker push myregistry/myimage:$version
  • 19.
    Continuous Deployment withdocker Deploy stage : ● Connect to the swarm (export DOCKER_HOST, ...) ● docker-compose pull ● docker-compose up -d
  • 20.
    Conclusion If you planto do a twelve-factor app use docker to make it