This document discusses how Docker can help developers implement the 12-factor app methodology for building cloud-native applications. It outlines the 12 principles of a 12-factor app and how Docker addresses each principle, such as ensuring portability and scalability across environments through containerization. The document then provides a step-by-step guide for implementing a 12-factor app with Docker, covering aspects like codebase management, dependencies, configuration, processes, networking, logs, and continuous deployment.
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 can help ?
● Maximum portability between environments
● Suitable for deployment on modern cloud platforms
● Scale up
● Minimize time and costs with automation
● Continuous deployment
4. 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
7. |||. Config
Store config in the environment
● Linux environment variables
● docker-compose can define env variables via env files
8. 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
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 the app as one or more stateless
processes
● docker enforces stateless processes
● Use volumes to persist data
11. Export services via port binding
VII. Port Binding
Docker Host
service network
container
http
container
php-fpm
container
mysql
port binding
12. 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
13. 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
14. X. Dev/Prod parity
Keep development, staging, and
production as similar as possible
● “build once, run anywhere”
● Same app images across DevOps stages
15. 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