SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
DevOPS – Day 2
Thursday, June 2th 2016
Questions since the previous workshop?
What is a container?
• Program executed in a limited kernel resources
• Cgroups: CPU, Memory, Network, …
• Namespace: Process, User, Filesystem, ...
• Union file system: Filesystem
Virtual machine vs Container
Server
OS
Hypervisor
Guest OS
Libraries
App 1
Server
OS
Docker Engine
Guest OS Guest OS
Libraries Libraries
App 2 App 3
Libraries
App 1
Libraries Libraries
App 2 App 3
Containers for developers
• Micro service paradigm
• Environment variables for application configuration
User
Contract
Support
Notification
Analytics
Invoice
Storage
Task
Containers for system engineers
• Blue/Green deployment
• High level management
• Security issues
• Change all tools…
User
Load balancer
A version
B version
A version
B version
A version
B version
Web server Application Database
Docker
Very active project…
You must read release notes and check technical details!
Docker softwares
Docker
Engine
Docker
Machine
Docker
Registry
Docker
Compose
Kitematic
Docker Toolbox
Automate Docker
provisioning
Desktop GUI for
Docker
Multi-container
orchestration tool
Run Docker
container
Docker containers
hosted registry
Helper to install Docker
components on desktop
Docker
Cloud
Hosted service for
building and
deployingcontainers
Docker
Swarm
Host clustering
and container
scheduling
Dockerfile
• Dockerfile is a document composed of various commands to assemble
an image
• Inherit from on a base image
Dockerfile
FROM ubuntu
MAINTAINER SvenDowideit@docker.com
RUN apt-key adv --keyserverhkp://p80.pool.sks-keyservers.net:80--recv-keys
B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdgmain">/etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3
postgresql-contrib-9.3
USER postgres
RUN /etc/init.d/postgresqlstart &&
psql --command "CREATE USER dockerWITH SUPERUSER PASSWORD 'docker';"&&
createdb -O dockerdocker
RUN echo "host all all 0.0.0.0/0 md5">> /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'">> /etc/postgresql/9.3/main/postgresql.conf
EXPOSE 5432
VOLUME ["/etc/postgresql","/var/log/postgresql","/var/lib/postgresql"]
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
Base image
Maintainer information
Install requirements
Set user to use when
running the image
Application configuration
Export port on network
Export volumes
Start application
Docker compose
• Compose is a tool for defining and running multi-container Docker
applications
• /! 2 versions of docker-compose format
docker-compose.yml (version 1)
postgres :
image: postgres
cron:
build: .
dockerfile: Dockerfile-cron
links:
- postgres
web:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
links:
- postgres
PostgreSQLdatabase
CRON container
Load volume from
current directory
Expose ports
Link containers
docker-compose.yml (version 2)
version: '2’
services:
web:
build: .
ports:
- ”8000:8000"
volumes:
- .:/code
- logvolume01:/var/log
depends_on:
- postgresql
postgres:
image: postgres
volumes:
logvolume01: {}
Version
Application
Postgresql
Volumes
Running containers with Docker composer
1. Define application container
Create Dockerfile
2. Define container relations
Create docker-compose.yml
3. Start containers
docker-compose up
4. Execute commands
docker-compose run <container> <cmd>
Let’s try Docker…
Install Docker Toolbox
• Docker Toolbox’ll install all tools
• https://www.docker.com/products/docker-toolbox
Virtualbox
Virtual machine
Docker Engine
Docker Machine
Docker CLI client
Docker Composer
Container
Create your first container
• Start Docker server
docker-machine start default
• Load Docker connection parameters
eval $(docker-machine env default)
• Create Dockerfile
FROM php
WORKDIR /var/www
ADD index.php .
EXPOSE 8080
ENTRYPOINT ["php", "-S", "0.0.0.0:8080"]
Start your first container
• Create index.php
echo '<?php echo ”Good morning!n”; ?>' > index.php
• Build container
docker build -t app1 .
• Check images
docker images | head
• Run the container
docker run -t app1 -p 8080:8080 app1
• Connect to the website
curl -v $(docker-machine ip):8080
Update the container
• Update application content
echo '<?php echo "Welcome!n”;?>' > index.php
• Connect to the website
curl -v $(docker-machine ip):8080
• Still Good morning… What’s wrong?
• Restart your container
Share your container
• Create an account on https://hub.docker.com
• Tag your container
docker tag app1 <username>/app1
• Connect on Dockerhub
docker login
• Push container to Docker Hub
docker push <username>/app1
• Connect on DockerHub website
https://hub.docker.com/<username>/app1/
cAdvisor
• Created by Google to monitor their own containers (lmctfy)
• Analyzes resource usage and performance characteristics of running
containers.
Start cAdvisor
• Run cAdvisor
docker run 
--name=cadvisor 
--restart always 
--detach=true
--volume=/:/rootfs:ro
--volume=/var/run:/var/run:rw 
--volume=/sys:/sys:ro
--volume=/var/lib/docker/:/var/lib/docker:ro 
--publish=8001:8080 
google/cadvisor:latest
• Connect to the web interface
http://192.168.99.100:8001
Unit tests
Continuous integration/deployment
• Continuous integration
• Run tests for each commit
• Detect bugs
• Continuous deployment
• Deploy application if tests success
GIT repository
CI CD
ProductionStaging
Developer
Gitlab
• Open source GIT repository management solution
• Community and Enterprise editions
• GitHub alternative
• https://about.gitlab.com
Start GitLab
• Run GitLab
docker run --detach
--hostname gitlab.example.com
--publish8000:80 
--name gitlab
--restart always 
--volume /srv/gitlab/config:/etc/gitlab
--volume /srv/gitlab/logs:/var/log/gitlab
--volume /srv/gitlab/data:/var/opt/gitlab
gitlab/gitlab-ce:latest
• Connect to the web interface(Default password: root/5iveL!fe)
http://$(docker-machine ip):8000
Configure GitLab
• Connect on GitLab interface
• Create a project
• Create a user for Jenkins
Clone the repository
git clone http://192.168.99.100:8000/root/app1.git
cd app1/
echo 'Welcome' > README.md
git add README.md
git commit README.md -m 'Add README.md'
git push
Jenkins
• The most popular tool to build and deploy projects
• Unittest
• Continuous Integration
• Continuous Delivery
• Plugins for everything!
• Distribute work across multiple machines
• https://jenkins.io
Start Jenkins
• Run Jenkins
docker run --detach 
--publish 10000:8080 
--name jenkins 
--restart always 
jenkins:latest
• Connect to the web interface
http://$(docker-machine ip):10000
Configure Jenkins
• Install “Git plugin”
• Restart Jenkins
• Create a new project called “App1 - master”
• Add GIT credentials
• Poll SCM
* * * * *
• Execute
phpunit -c app
Lunch break!
Evaluation
Create a web hit counter with containers
Docker Engine
Redis
PHP application
Technical details
• 2 Docker containers:
• Redis
• Application (PHP application)
• Use PHP composer to install requirements
• Use Docker Compose to start containers
• Bonus:
• 3 tiers architecture (Nginx/PHP/Redis)
• SSL
• Unit tests
• …
Solution
Application files
<?php
require __DIR__. '/vendor/autoload.php';
PredisAutoloader::register();
// Connect to redis
try {
$redis = new PredisClient('tcp://redis:6379');
}
catch (Exception $error){
die($error->getMessage());
}
// Get visitors
$visitors = ($redis->exists('visitors')) ? $redis->get('visitors'): 0;
// Increment visitors
$visitors++;
$redis->set('visitors',$visitors);
// Display visitors
if ($visitors > 1) {
echo "<h1>There are$visitors visitors!</h1>n";
} else {
echo "<h1>There is $visitors visitor!</h1>n";
}
?>
{
"require": {
"predis/predis": "^1.0.3"
}
}
index.php composer.json
Docker files
FROM php:5-apache
# Install GIT
RUN apt-get update
&& apt-getinstall -ygit 
&& apt-getclean
&& rm -rf/var/lib/apt/lists/*
# Install PHP composer
RUN curl -sS https://getcomposer.org/installer | php ----install-dir=/usr/local/bin --
filename=composer
WORKDIR /var/www/html
# Add application
ADD . /var/www/html/
# Install applicationrequirements with PHP composer
RUN composer install
version: '2'
services:
application:
build: .
ports:
- "80:80"
depends_on:
- redis
redis:
image: redis:latest
Dockerfile docker-compose.yml
Q&A

Más contenido relacionado

La actualidad más candente

Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker, Inc.
 

La actualidad más candente (20)

Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
Building Distributed Systems without Docker, Using Docker Plumbing Projects -...Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
 
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
Docker Platform and Ecosystem Nov 2015
Docker Platform and Ecosystem Nov 2015Docker Platform and Ecosystem Nov 2015
Docker Platform and Ecosystem Nov 2015
 
Devoxx 2016 - Docker Nuts and Bolts
Devoxx 2016 - Docker Nuts and BoltsDevoxx 2016 - Docker Nuts and Bolts
Devoxx 2016 - Docker Nuts and Bolts
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
 
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
Docker-Hanoi @DKT , Presentation about Docker EcosystemDocker-Hanoi @DKT , Presentation about Docker Ecosystem
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
 
What's new in Docker - InfraKit - Docker Meetup Berlin 2016
What's new in Docker - InfraKit - Docker Meetup Berlin 2016What's new in Docker - InfraKit - Docker Meetup Berlin 2016
What's new in Docker - InfraKit - Docker Meetup Berlin 2016
 
Dockers zero to hero
Dockers zero to heroDockers zero to hero
Dockers zero to hero
 
Docker Hub Breakout Session at DockerCon by Ken Cochrane
Docker Hub Breakout Session at DockerCon by Ken CochraneDocker Hub Breakout Session at DockerCon by Ken Cochrane
Docker Hub Breakout Session at DockerCon by Ken Cochrane
 
Advanced Docker Developer Workflows on MacOS X and Windows
Advanced Docker Developer Workflows on MacOS X and WindowsAdvanced Docker Developer Workflows on MacOS X and Windows
Advanced Docker Developer Workflows on MacOS X and Windows
 
Docker and Containers overview - Docker Workshop
Docker and Containers overview - Docker WorkshopDocker and Containers overview - Docker Workshop
Docker and Containers overview - Docker Workshop
 
Managing Open Source software in the Docker era
Managing Open Source software in the Docker era Managing Open Source software in the Docker era
Managing Open Source software in the Docker era
 
DCEU 18: How To Build Your Containerization Strategy
DCEU 18: How To Build Your Containerization StrategyDCEU 18: How To Build Your Containerization Strategy
DCEU 18: How To Build Your Containerization Strategy
 
Docker - 15 great Tutorials
Docker - 15 great TutorialsDocker - 15 great Tutorials
Docker - 15 great Tutorials
 
DockerCon SF 2015: Keynote Day 1
DockerCon SF 2015: Keynote Day 1DockerCon SF 2015: Keynote Day 1
DockerCon SF 2015: Keynote Day 1
 
Docker Platform and Ecosystem
Docker Platform and EcosystemDocker Platform and Ecosystem
Docker Platform and Ecosystem
 
Microservices using relocatable Docker containers
Microservices using relocatable Docker containersMicroservices using relocatable Docker containers
Microservices using relocatable Docker containers
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Aws ug dxb 2021 container series iv
Aws ug dxb 2021 container series  ivAws ug dxb 2021 container series  iv
Aws ug dxb 2021 container series iv
 

Destacado

Destacado (6)

DevOPS training - Day 1/2
DevOPS training - Day 1/2DevOPS training - Day 1/2
DevOPS training - Day 1/2
 
Enterprise DevOps: Crossing the Great Divide with DevOps Training
Enterprise DevOps: Crossing the Great Divide with DevOps TrainingEnterprise DevOps: Crossing the Great Divide with DevOps Training
Enterprise DevOps: Crossing the Great Divide with DevOps Training
 
Key note "Developing MOOCs for continuous professional training and developm...
Key note "Developing MOOCs  for continuous professional training and developm...Key note "Developing MOOCs  for continuous professional training and developm...
Key note "Developing MOOCs for continuous professional training and developm...
 
Devops training in Hyderabad
Devops training in HyderabadDevops training in Hyderabad
Devops training in Hyderabad
 
DevOps for Enterprise Systems - Sanjay Chandru
DevOps for Enterprise Systems - Sanjay ChandruDevOps for Enterprise Systems - Sanjay Chandru
DevOps for Enterprise Systems - Sanjay Chandru
 
Devops Online Training - Edubodhi
Devops Online Training - EdubodhiDevops Online Training - Edubodhi
Devops Online Training - Edubodhi
 

Similar a DevOPS training - Day 2/2

Before & After Docker Init
Before & After Docker InitBefore & After Docker Init
Before & After Docker Init
Angel Borroy López
 

Similar a DevOPS training - Day 2/2 (20)

Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
Docker fundamentals
Docker fundamentalsDocker fundamentals
Docker fundamentals
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
 
Before & After Docker Init
Before & After Docker InitBefore & After Docker Init
Before & After Docker Init
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
 
Docker, but what it is?
Docker, but what it is?Docker, but what it is?
Docker, but what it is?
 
OpenStack Summit
OpenStack SummitOpenStack Summit
OpenStack Summit
 
Docker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on Azure
Docker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on AzureDocker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on Azure
Docker Seattle Meetup April 2015 - The Docker Orchestration Ecosystem on Azure
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and Microservice
 
Continuous Delivery with Docker and Amazon ECS
Continuous Delivery with Docker and Amazon ECSContinuous Delivery with Docker and Amazon ECS
Continuous Delivery with Docker and Amazon ECS
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - Technical
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
WSO2ConEU 2016 Tutorial - Deploying WSO2 Middleware on Containers
WSO2ConEU 2016 Tutorial - Deploying WSO2 Middleware on ContainersWSO2ConEU 2016 Tutorial - Deploying WSO2 Middleware on Containers
WSO2ConEU 2016 Tutorial - Deploying WSO2 Middleware on Containers
 
Deploying WSO2 Middleware on Containers
Deploying WSO2 Middleware on ContainersDeploying WSO2 Middleware on Containers
Deploying WSO2 Middleware on Containers
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 

Último

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 

DevOPS training - Day 2/2

  • 1. DevOPS – Day 2 Thursday, June 2th 2016
  • 2. Questions since the previous workshop?
  • 3. What is a container? • Program executed in a limited kernel resources • Cgroups: CPU, Memory, Network, … • Namespace: Process, User, Filesystem, ... • Union file system: Filesystem
  • 4. Virtual machine vs Container Server OS Hypervisor Guest OS Libraries App 1 Server OS Docker Engine Guest OS Guest OS Libraries Libraries App 2 App 3 Libraries App 1 Libraries Libraries App 2 App 3
  • 5. Containers for developers • Micro service paradigm • Environment variables for application configuration User Contract Support Notification Analytics Invoice Storage Task
  • 6. Containers for system engineers • Blue/Green deployment • High level management • Security issues • Change all tools… User Load balancer A version B version A version B version A version B version Web server Application Database
  • 8. Very active project… You must read release notes and check technical details!
  • 9. Docker softwares Docker Engine Docker Machine Docker Registry Docker Compose Kitematic Docker Toolbox Automate Docker provisioning Desktop GUI for Docker Multi-container orchestration tool Run Docker container Docker containers hosted registry Helper to install Docker components on desktop Docker Cloud Hosted service for building and deployingcontainers Docker Swarm Host clustering and container scheduling
  • 10. Dockerfile • Dockerfile is a document composed of various commands to assemble an image • Inherit from on a base image
  • 11. Dockerfile FROM ubuntu MAINTAINER SvenDowideit@docker.com RUN apt-key adv --keyserverhkp://p80.pool.sks-keyservers.net:80--recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdgmain">/etc/apt/sources.list.d/pgdg.list RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 USER postgres RUN /etc/init.d/postgresqlstart && psql --command "CREATE USER dockerWITH SUPERUSER PASSWORD 'docker';"&& createdb -O dockerdocker RUN echo "host all all 0.0.0.0/0 md5">> /etc/postgresql/9.3/main/pg_hba.conf RUN echo "listen_addresses='*'">> /etc/postgresql/9.3/main/postgresql.conf EXPOSE 5432 VOLUME ["/etc/postgresql","/var/log/postgresql","/var/lib/postgresql"] CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"] Base image Maintainer information Install requirements Set user to use when running the image Application configuration Export port on network Export volumes Start application
  • 12. Docker compose • Compose is a tool for defining and running multi-container Docker applications • /! 2 versions of docker-compose format
  • 13. docker-compose.yml (version 1) postgres : image: postgres cron: build: . dockerfile: Dockerfile-cron links: - postgres web: build: . volumes: - .:/code ports: - "8000:8000" links: - postgres PostgreSQLdatabase CRON container Load volume from current directory Expose ports Link containers
  • 14. docker-compose.yml (version 2) version: '2’ services: web: build: . ports: - ”8000:8000" volumes: - .:/code - logvolume01:/var/log depends_on: - postgresql postgres: image: postgres volumes: logvolume01: {} Version Application Postgresql Volumes
  • 15. Running containers with Docker composer 1. Define application container Create Dockerfile 2. Define container relations Create docker-compose.yml 3. Start containers docker-compose up 4. Execute commands docker-compose run <container> <cmd>
  • 17. Install Docker Toolbox • Docker Toolbox’ll install all tools • https://www.docker.com/products/docker-toolbox Virtualbox Virtual machine Docker Engine Docker Machine Docker CLI client Docker Composer Container
  • 18. Create your first container • Start Docker server docker-machine start default • Load Docker connection parameters eval $(docker-machine env default) • Create Dockerfile FROM php WORKDIR /var/www ADD index.php . EXPOSE 8080 ENTRYPOINT ["php", "-S", "0.0.0.0:8080"]
  • 19. Start your first container • Create index.php echo '<?php echo ”Good morning!n”; ?>' > index.php • Build container docker build -t app1 . • Check images docker images | head • Run the container docker run -t app1 -p 8080:8080 app1 • Connect to the website curl -v $(docker-machine ip):8080
  • 20. Update the container • Update application content echo '<?php echo "Welcome!n”;?>' > index.php • Connect to the website curl -v $(docker-machine ip):8080 • Still Good morning… What’s wrong? • Restart your container
  • 21. Share your container • Create an account on https://hub.docker.com • Tag your container docker tag app1 <username>/app1 • Connect on Dockerhub docker login • Push container to Docker Hub docker push <username>/app1 • Connect on DockerHub website https://hub.docker.com/<username>/app1/
  • 22. cAdvisor • Created by Google to monitor their own containers (lmctfy) • Analyzes resource usage and performance characteristics of running containers.
  • 23. Start cAdvisor • Run cAdvisor docker run --name=cadvisor --restart always --detach=true --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8001:8080 google/cadvisor:latest • Connect to the web interface http://192.168.99.100:8001
  • 25. Continuous integration/deployment • Continuous integration • Run tests for each commit • Detect bugs • Continuous deployment • Deploy application if tests success GIT repository CI CD ProductionStaging Developer
  • 26. Gitlab • Open source GIT repository management solution • Community and Enterprise editions • GitHub alternative • https://about.gitlab.com
  • 27. Start GitLab • Run GitLab docker run --detach --hostname gitlab.example.com --publish8000:80 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest • Connect to the web interface(Default password: root/5iveL!fe) http://$(docker-machine ip):8000
  • 28. Configure GitLab • Connect on GitLab interface • Create a project • Create a user for Jenkins
  • 29. Clone the repository git clone http://192.168.99.100:8000/root/app1.git cd app1/ echo 'Welcome' > README.md git add README.md git commit README.md -m 'Add README.md' git push
  • 30. Jenkins • The most popular tool to build and deploy projects • Unittest • Continuous Integration • Continuous Delivery • Plugins for everything! • Distribute work across multiple machines • https://jenkins.io
  • 31. Start Jenkins • Run Jenkins docker run --detach --publish 10000:8080 --name jenkins --restart always jenkins:latest • Connect to the web interface http://$(docker-machine ip):10000
  • 32. Configure Jenkins • Install “Git plugin” • Restart Jenkins • Create a new project called “App1 - master” • Add GIT credentials • Poll SCM * * * * * • Execute phpunit -c app
  • 34. Evaluation Create a web hit counter with containers
  • 36. Technical details • 2 Docker containers: • Redis • Application (PHP application) • Use PHP composer to install requirements • Use Docker Compose to start containers • Bonus: • 3 tiers architecture (Nginx/PHP/Redis) • SSL • Unit tests • …
  • 38. Application files <?php require __DIR__. '/vendor/autoload.php'; PredisAutoloader::register(); // Connect to redis try { $redis = new PredisClient('tcp://redis:6379'); } catch (Exception $error){ die($error->getMessage()); } // Get visitors $visitors = ($redis->exists('visitors')) ? $redis->get('visitors'): 0; // Increment visitors $visitors++; $redis->set('visitors',$visitors); // Display visitors if ($visitors > 1) { echo "<h1>There are$visitors visitors!</h1>n"; } else { echo "<h1>There is $visitors visitor!</h1>n"; } ?> { "require": { "predis/predis": "^1.0.3" } } index.php composer.json
  • 39. Docker files FROM php:5-apache # Install GIT RUN apt-get update && apt-getinstall -ygit && apt-getclean && rm -rf/var/lib/apt/lists/* # Install PHP composer RUN curl -sS https://getcomposer.org/installer | php ----install-dir=/usr/local/bin -- filename=composer WORKDIR /var/www/html # Add application ADD . /var/www/html/ # Install applicationrequirements with PHP composer RUN composer install version: '2' services: application: build: . ports: - "80:80" depends_on: - redis redis: image: redis:latest Dockerfile docker-compose.yml
  • 40. Q&A