SlideShare a Scribd company logo
1 of 28
Download to read offline
Dockerize a small
business
HOW DOCKER TRANSFORM OUR DEVELOPMENT & DEPLOYMENT
PROCESS
Contents
• The Dark age (Why Docker and Container matter)
• The Dockerization progress (How Docker fits in)
• Practice time
• Some useful recipes
• Example 1: Setup your own CI environments
• Example 2: Fantasy Football App
The Dark age
Modern “app” requirements
Not so thin front end app on various clients: browser, mobile, tablet
Assemble many different services from inside/outside sources
Running on any available set of physical resources (public/private/virtualized)
Modern “app” requirements
How to setup development environment fast and reliable
How to ensure services interact consistently, avoids dependencies hell
How to avoids NxN different configs
How to migrate and scale quickly, ensure compatibility across different deployment
environments
NxN compatibility nightmare
MULTIPLICITY OF STACKS
nginx + modsecurity + openssl
postgresql + postgis
hadoop + hive + thrift + OpenJDK
Ruby + Rails + sass + Unicorn
Redis + redis-sentinel
Python 3 + celery + pyredis + libcurl +
ffmpeg + libopencv + nodejs + phantomjs
Python 2.7 + Flask + pyredis + celery +
psycopg + postgresql-client
MULTIPLICITY OF DEPLOYMENT
ENVIRONMENTS
Development VM Public Cloud
Contributor’s laptop
Production Servers Production Cluster
Customer Data Center
Centos Ubuntu Debian
5 years running without package update
Outdate kernel Weird lib path
Custom repositories that no one maintained
isolation = k * repeatability
Where k is a constant that is inversely proportional to the probability of you saying "It works on
my machine".
Multiple tools for every stack to solve the isolation problem
◦ Compile your Python + virtualenv + pip + buildout + supervisord
◦ Rbenv + bundle + foreman + Capistrano + foreman
“This is like having sex with two condoms and anticonception pills.”
Still there will be inconsistency
◦ Incomplete version locks file
◦ Download cache in local machine
◦ Lack of / different version of C/C++ devel packages
Also, It takes hours to setup the environments
My code’s compiling
Virtualization saves the day
A virtual server for each app
Consistent environment
Easier for management (backup/migrate/increase resource …)
Vagrant automate dev environment setup
…for a price!
Heavy weight / expensive / slow
Different VMs for different hypervisors
Image migration between different infrastructure/PaaS providers was/is quite painful
Resource allocation is not good enough
Still takes time to setup
People need something even more lightweight/atomic
Container is the future
And Docker popularized the technology
◦ Can encapsulate almost everything and its dependencies
◦ Run consistently on any hardware without modification
◦ Resource, network and content isolation
◦ Almost no resource overhead
◦ Good set of operation: run, start, stop, commit, pull, search… Perfect for CI, CD, auto scaling, hybrid
clouds…
◦ Separation of duty: Dev worries about code, Ops worries about infrastructure
Why dev care: Build once, run anywhere
A clean, safe, hygienic and portable runtime environment for your app.
Run each app in its own isolated container, so you can run various versions of libraries and other
dependencies for each app without worrying
Reduce/eliminate concerns about compatibility on different platforms
Cheap, zero-penalty containers to deploy services
Instant replay and reset of image snapshots
Why ops care: Configure once, run
anything
Make the entire lifecycle more efficient, consistent, and repeatable
Eliminate inconsistencies between development, test, production, and customer environments
Significantly improves the speed and reliability of continuous deployment and continuous
integration systems
Because the containers are so lightweight, address significant performance, costs, deployment,
and portability issues normally associated with VMs
The Dockerization
progress
Use Docker as new building block
Thinks Service and Volume
Design apps as multiple services talk with each others via API
Each service run in 1 or multiple, replicated containers
No containers run multiple services
Design persistent bits of app as multiple volumes
A service can either rw or ro a volume
Dev describes services and dependencies via compose file
New dev use compose file to setup dev environment
Ops look at the compose file and translate/create platform specific service configuration files.
Docker-powered process
Dev
Github
Local, private
reposistory
CI service
Build image
with src
Run tests
in image
Dev
Bootstrap project with
Dockerfile and
docker-compose.yml
Clone project
$ docker-compose up
Docker-powered process
Ops
Github
Docker
reposistory
CI service
Public/private
container service
image
Build image
with src
Run tests
in image Services
configuration
Run services
Bootstrap a new project
Dev create new project with Dockerfile and docker-compose.yml
Dev declare dependencies and external services through docker-compose.yml
◦ Services start with build: . will have a .: /app volume
Dev add test/CI related files and push to github
The image is built and pushed to private docker registry
Join an ongoing project
Dev clone the repository
Dev download necessary volumes from other dev/staging server (db, configuration etc)
$ docker-compose up
Deploy and scale services
Ops look at the docker-compose file and create necessary services on the production docker
environment
Ops configure the volume storage options (nfs, ebs …)
Ops configure the forward proxy (nginx, certbot, load balancing…)
Ops run multiple containers base on the built image
Update and migrate
New app image is built and pushed into registry.
New containers are sequentially created and replace the old ones (rolling update).
If there is data need to be migrated (scheduled downtime):
◦ Stop the gateway (nginx)
◦ Hot backup the data volumes
◦ Run the migration scripts
◦ Restart the gateway
◦ Fall back is easy and instant since both old data volumes and images are there
Practice
SOME RECIPES TO BOOTSTRAP YOUR OWN DOCKERIZATION.
Docker cluster setup
#Install docker on both master and workers
yum update -y
curl -fsSL https://get.docker.com/ | sh
#Start & Enable docker service
systemctl start docker; systemctl enable docker
#On the master, Init the swarm, we don't want outsider join our swarm.
docker swarm init --listen-addr $PRIVATE_IP:2377
#On the workers, join the swarm, command is outputted from last command
docker swarm join --secret $SECRET --ca-hash $HASH $MASTER_IP:2377
#Create a services, scale the services
docker service create -p 80:8000 --name whoami jwilder/whoami
docker service scale whoami=2
#Wait containers being created and test it with curl
Nginx and Certbot
mkdir /opt/nginx
docker run -d --name nginx nginx
docker cp nginx:/etc/nginx /opt/nginx/etc
docker cp nginx:/usr/share/nginx/html /opt/nginx/www
docker stop nginx; docker rm nginx
docker run –d --name nginx --restart=always 
-p 80:80 –p 443:443 
-v /opt/nginx/etc:/etc/nginx 
-v /opt/nginx/www:/usr/share/nginx/html nginx
docker run -it --rm 
-v /opt/nginx/etc/certs:/etc/letsencrypt 
-v /opt/nginx/www:/www 
gzm55/certbot certonly --webroot -w /www –d example.com –d www.example.com
crontab –e
30 2 * * 1 docker run -it --rm -v /opt/nginx/certs:/etc/letsencrypt -v /opt/nginx/www:/www gzm55/certbot renew
>> /var/log/certbot.log
35 2 * * 1 docker exec nginx nginx -s reload
Rails quickstart
DOCKERFILE
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install
-y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
DOCKER-COMPOSE
version: '2’
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000
-b '0.0.0.0‘
volumes:
- .:/myapp
ports:
- "3000:3000“
depends_on:
- db
Python quickstart
DOCKERFILE
FROM python:2.7
RUN mkdir /myapp
WORKDIR /myapp
ADD requirements.txt /myapp/
RUN pip install -r requirements.txt
ADD . /myapp/
DOCKER-COMPOSE
version: '2'
services:
db:
image: postgres
web:
build: .
command: python app.py
volumes:
- .:/myapp
ports:
- "5000:5000"
depends_on:
- db
Your own CI environment
Fantasy football apps

More Related Content

What's hot

What's hot (20)

Intro to docker - innovation demo 2022
Intro to docker - innovation demo 2022Intro to docker - innovation demo 2022
Intro to docker - innovation demo 2022
 
Docker for .NET Developers - Michele Leroux Bustamante, Solliance
Docker for .NET Developers - Michele Leroux Bustamante, SollianceDocker for .NET Developers - Michele Leroux Bustamante, Solliance
Docker for .NET Developers - Michele Leroux Bustamante, Solliance
 
Docker on Docker
Docker on DockerDocker on Docker
Docker on Docker
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker basics
Docker basicsDocker basics
Docker basics
 
Docker & Kubernetes intro
Docker & Kubernetes introDocker & Kubernetes intro
Docker & Kubernetes intro
 
DCSF19 How To Build Your Containerization Strategy
DCSF19 How To Build Your Containerization Strategy  DCSF19 How To Build Your Containerization Strategy
DCSF19 How To Build Your Containerization Strategy
 
Docker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EEDocker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EE
 
DCSF19 Containers for Beginners
DCSF19 Containers for BeginnersDCSF19 Containers for Beginners
DCSF19 Containers for Beginners
 
Structured Container Delivery by Oscar Renalias, Accenture
Structured Container Delivery by Oscar Renalias, AccentureStructured Container Delivery by Oscar Renalias, Accenture
Structured Container Delivery by Oscar Renalias, Accenture
 
Continuous Integration with Docker on AWS
Continuous Integration with Docker on AWSContinuous Integration with Docker on AWS
Continuous Integration with Docker on AWS
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura Frank
 
Docker and stuff
Docker and stuffDocker and stuff
Docker and stuff
 
Docker Container As A Service - March 2016
Docker Container As A Service - March 2016Docker Container As A Service - March 2016
Docker Container As A Service - March 2016
 
Highly Available Persistent Applications in Containers by Kendrick Coleman, E...
Highly Available Persistent Applications in Containers by Kendrick Coleman, E...Highly Available Persistent Applications in Containers by Kendrick Coleman, E...
Highly Available Persistent Applications in Containers by Kendrick Coleman, E...
 
Node.js Rocks in Docker for Dev and Ops
Node.js Rocks in Docker for Dev and OpsNode.js Rocks in Docker for Dev and Ops
Node.js Rocks in Docker for Dev and Ops
 
Docker?!?! But I'm a SysAdmin
Docker?!?! But I'm a SysAdminDocker?!?! But I'm a SysAdmin
Docker?!?! But I'm a SysAdmin
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
 
Docker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&ADocker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&A
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 

Similar to ContainerDayVietnam2016: Dockerize a small business

Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
Erica Windisch
 

Similar to ContainerDayVietnam2016: Dockerize a small business (20)

PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
 
Docker dev ops for cd meetup 12-14
Docker dev ops for cd meetup 12-14Docker dev ops for cd meetup 12-14
Docker dev ops for cd meetup 12-14
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
 
Accelerate your development with Docker
Accelerate your development with DockerAccelerate your development with Docker
Accelerate your development with Docker
 
Accelerate your software development with Docker
Accelerate your software development with DockerAccelerate your software development with Docker
Accelerate your software development with Docker
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with docker
 
Docker, Cloud Foundry, Bosh & Bluemix
Docker, Cloud Foundry, Bosh & BluemixDocker, Cloud Foundry, Bosh & Bluemix
Docker, Cloud Foundry, Bosh & Bluemix
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxData
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and Microservice
 
Docker team training
Docker team trainingDocker team training
Docker team training
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
Docker 1.9 Workshop
Docker 1.9 WorkshopDocker 1.9 Workshop
Docker 1.9 Workshop
 
DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline  DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline
 
Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
Practical Docker for OpenStack - NYC / PHL OpenStack meetup (4-23-2014)
 
Docker In Brief
Docker In BriefDocker In Brief
Docker In Brief
 
DevAssistant, Docker and You
DevAssistant, Docker and YouDevAssistant, Docker and You
DevAssistant, Docker and You
 
Docker
DockerDocker
Docker
 
Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
 
Docker for dev
Docker for devDocker for dev
Docker for dev
 

More from Docker-Hanoi

More from Docker-Hanoi (17)

ContainerDayVietnam2016: Lesson Leanred on Docker 1.12 and Swarm Mode
ContainerDayVietnam2016: Lesson Leanred on Docker 1.12 and Swarm ModeContainerDayVietnam2016: Lesson Leanred on Docker 1.12 and Swarm Mode
ContainerDayVietnam2016: Lesson Leanred on Docker 1.12 and Swarm Mode
 
ContainerDayVietnam2016: Docker 1.12 at OpenFPT
ContainerDayVietnam2016: Docker 1.12 at OpenFPTContainerDayVietnam2016: Docker 1.12 at OpenFPT
ContainerDayVietnam2016: Docker 1.12 at OpenFPT
 
Azure Container Service
Azure Container ServiceAzure Container Service
Azure Container Service
 
Docker-Ha Noi- Year end 2015 party
Docker-Ha Noi- Year end 2015 partyDocker-Ha Noi- Year end 2015 party
Docker-Ha Noi- Year end 2015 party
 
DockerDay2015: Introduction to OpenStack Magnum
DockerDay2015: Introduction to OpenStack MagnumDockerDay2015: Introduction to OpenStack Magnum
DockerDay2015: Introduction to OpenStack Magnum
 
DockerDay2015: Keynote
DockerDay2015: KeynoteDockerDay2015: Keynote
DockerDay2015: Keynote
 
DockerDay2015: Deploy Apps on IBM Bluemix
DockerDay2015: Deploy Apps on IBM BluemixDockerDay2015: Deploy Apps on IBM Bluemix
DockerDay2015: Deploy Apps on IBM Bluemix
 
DockerDay2015: Docker Security
DockerDay2015: Docker SecurityDockerDay2015: Docker Security
DockerDay2015: Docker Security
 
DockerDay2015: Docker orchestration for developers
DockerDay2015: Docker orchestration for developersDockerDay2015: Docker orchestration for developers
DockerDay2015: Docker orchestration for developers
 
DockerDay2015: Docker Networking
DockerDay2015: Docker NetworkingDockerDay2015: Docker Networking
DockerDay2015: Docker Networking
 
DockerDay2015: Docker orchestration for sysadmin
DockerDay2015: Docker orchestration for sysadminDockerDay2015: Docker orchestration for sysadmin
DockerDay2015: Docker orchestration for sysadmin
 
DockerDay2015: Getting started with Google Container Engine
DockerDay2015: Getting started with Google Container EngineDockerDay2015: Getting started with Google Container Engine
DockerDay2015: Getting started with Google Container Engine
 
DockerDay2015: Build and monitor a load balanced web application with Docker ...
DockerDay2015: Build and monitor a load balanced web application with Docker ...DockerDay2015: Build and monitor a load balanced web application with Docker ...
DockerDay2015: Build and monitor a load balanced web application with Docker ...
 
DockerDay2015: Introduction to Dockerfile
DockerDay2015: Introduction to DockerfileDockerDay2015: Introduction to Dockerfile
DockerDay2015: Introduction to Dockerfile
 
DockerDay2015: Getting started with Docker
DockerDay2015: Getting started with DockerDockerDay2015: Getting started with Docker
DockerDay2015: Getting started with Docker
 
DockerDay2015: Microsoft and Docker
DockerDay2015: Microsoft and DockerDockerDay2015: Microsoft and Docker
DockerDay2015: Microsoft and Docker
 
DockerDay 2015: From months to minutes - How GE appliances brought docker int...
DockerDay 2015: From months to minutes - How GE appliances brought docker int...DockerDay 2015: From months to minutes - How GE appliances brought docker int...
DockerDay 2015: From months to minutes - How GE appliances brought docker int...
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

ContainerDayVietnam2016: Dockerize a small business

  • 1. Dockerize a small business HOW DOCKER TRANSFORM OUR DEVELOPMENT & DEPLOYMENT PROCESS
  • 2. Contents • The Dark age (Why Docker and Container matter) • The Dockerization progress (How Docker fits in) • Practice time • Some useful recipes • Example 1: Setup your own CI environments • Example 2: Fantasy Football App
  • 4. Modern “app” requirements Not so thin front end app on various clients: browser, mobile, tablet Assemble many different services from inside/outside sources Running on any available set of physical resources (public/private/virtualized)
  • 5. Modern “app” requirements How to setup development environment fast and reliable How to ensure services interact consistently, avoids dependencies hell How to avoids NxN different configs How to migrate and scale quickly, ensure compatibility across different deployment environments
  • 6. NxN compatibility nightmare MULTIPLICITY OF STACKS nginx + modsecurity + openssl postgresql + postgis hadoop + hive + thrift + OpenJDK Ruby + Rails + sass + Unicorn Redis + redis-sentinel Python 3 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs + phantomjs Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client MULTIPLICITY OF DEPLOYMENT ENVIRONMENTS Development VM Public Cloud Contributor’s laptop Production Servers Production Cluster Customer Data Center Centos Ubuntu Debian 5 years running without package update Outdate kernel Weird lib path Custom repositories that no one maintained
  • 7. isolation = k * repeatability Where k is a constant that is inversely proportional to the probability of you saying "It works on my machine". Multiple tools for every stack to solve the isolation problem ◦ Compile your Python + virtualenv + pip + buildout + supervisord ◦ Rbenv + bundle + foreman + Capistrano + foreman “This is like having sex with two condoms and anticonception pills.” Still there will be inconsistency ◦ Incomplete version locks file ◦ Download cache in local machine ◦ Lack of / different version of C/C++ devel packages Also, It takes hours to setup the environments
  • 9. Virtualization saves the day A virtual server for each app Consistent environment Easier for management (backup/migrate/increase resource …) Vagrant automate dev environment setup
  • 10. …for a price! Heavy weight / expensive / slow Different VMs for different hypervisors Image migration between different infrastructure/PaaS providers was/is quite painful Resource allocation is not good enough Still takes time to setup People need something even more lightweight/atomic
  • 11. Container is the future And Docker popularized the technology ◦ Can encapsulate almost everything and its dependencies ◦ Run consistently on any hardware without modification ◦ Resource, network and content isolation ◦ Almost no resource overhead ◦ Good set of operation: run, start, stop, commit, pull, search… Perfect for CI, CD, auto scaling, hybrid clouds… ◦ Separation of duty: Dev worries about code, Ops worries about infrastructure
  • 12. Why dev care: Build once, run anywhere A clean, safe, hygienic and portable runtime environment for your app. Run each app in its own isolated container, so you can run various versions of libraries and other dependencies for each app without worrying Reduce/eliminate concerns about compatibility on different platforms Cheap, zero-penalty containers to deploy services Instant replay and reset of image snapshots
  • 13. Why ops care: Configure once, run anything Make the entire lifecycle more efficient, consistent, and repeatable Eliminate inconsistencies between development, test, production, and customer environments Significantly improves the speed and reliability of continuous deployment and continuous integration systems Because the containers are so lightweight, address significant performance, costs, deployment, and portability issues normally associated with VMs
  • 15. Use Docker as new building block Thinks Service and Volume Design apps as multiple services talk with each others via API Each service run in 1 or multiple, replicated containers No containers run multiple services Design persistent bits of app as multiple volumes A service can either rw or ro a volume Dev describes services and dependencies via compose file New dev use compose file to setup dev environment Ops look at the compose file and translate/create platform specific service configuration files.
  • 16. Docker-powered process Dev Github Local, private reposistory CI service Build image with src Run tests in image Dev Bootstrap project with Dockerfile and docker-compose.yml Clone project $ docker-compose up
  • 17. Docker-powered process Ops Github Docker reposistory CI service Public/private container service image Build image with src Run tests in image Services configuration Run services
  • 18. Bootstrap a new project Dev create new project with Dockerfile and docker-compose.yml Dev declare dependencies and external services through docker-compose.yml ◦ Services start with build: . will have a .: /app volume Dev add test/CI related files and push to github The image is built and pushed to private docker registry
  • 19. Join an ongoing project Dev clone the repository Dev download necessary volumes from other dev/staging server (db, configuration etc) $ docker-compose up
  • 20. Deploy and scale services Ops look at the docker-compose file and create necessary services on the production docker environment Ops configure the volume storage options (nfs, ebs …) Ops configure the forward proxy (nginx, certbot, load balancing…) Ops run multiple containers base on the built image
  • 21. Update and migrate New app image is built and pushed into registry. New containers are sequentially created and replace the old ones (rolling update). If there is data need to be migrated (scheduled downtime): ◦ Stop the gateway (nginx) ◦ Hot backup the data volumes ◦ Run the migration scripts ◦ Restart the gateway ◦ Fall back is easy and instant since both old data volumes and images are there
  • 22. Practice SOME RECIPES TO BOOTSTRAP YOUR OWN DOCKERIZATION.
  • 23. Docker cluster setup #Install docker on both master and workers yum update -y curl -fsSL https://get.docker.com/ | sh #Start & Enable docker service systemctl start docker; systemctl enable docker #On the master, Init the swarm, we don't want outsider join our swarm. docker swarm init --listen-addr $PRIVATE_IP:2377 #On the workers, join the swarm, command is outputted from last command docker swarm join --secret $SECRET --ca-hash $HASH $MASTER_IP:2377 #Create a services, scale the services docker service create -p 80:8000 --name whoami jwilder/whoami docker service scale whoami=2 #Wait containers being created and test it with curl
  • 24. Nginx and Certbot mkdir /opt/nginx docker run -d --name nginx nginx docker cp nginx:/etc/nginx /opt/nginx/etc docker cp nginx:/usr/share/nginx/html /opt/nginx/www docker stop nginx; docker rm nginx docker run –d --name nginx --restart=always -p 80:80 –p 443:443 -v /opt/nginx/etc:/etc/nginx -v /opt/nginx/www:/usr/share/nginx/html nginx docker run -it --rm -v /opt/nginx/etc/certs:/etc/letsencrypt -v /opt/nginx/www:/www gzm55/certbot certonly --webroot -w /www –d example.com –d www.example.com crontab –e 30 2 * * 1 docker run -it --rm -v /opt/nginx/certs:/etc/letsencrypt -v /opt/nginx/www:/www gzm55/certbot renew >> /var/log/certbot.log 35 2 * * 1 docker exec nginx nginx -s reload
  • 25. Rails quickstart DOCKERFILE FROM ruby:2.2.0 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /myapp WORKDIR /myapp ADD Gemfile /myapp/Gemfile ADD Gemfile.lock /myapp/Gemfile.lock RUN bundle install ADD . /myapp DOCKER-COMPOSE version: '2’ services: db: image: postgres web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0‘ volumes: - .:/myapp ports: - "3000:3000“ depends_on: - db
  • 26. Python quickstart DOCKERFILE FROM python:2.7 RUN mkdir /myapp WORKDIR /myapp ADD requirements.txt /myapp/ RUN pip install -r requirements.txt ADD . /myapp/ DOCKER-COMPOSE version: '2' services: db: image: postgres web: build: . command: python app.py volumes: - .:/myapp ports: - "5000:5000" depends_on: - db
  • 27. Your own CI environment