SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Dockerize Your Web
Application Stack
(PHP, MySQL and NginX)
Salman El Farisi
dev.salman.farisi@gmail.com
salman.farisi@badr-interactive.com
Lead Developer @ PT. Badr Interactive
What is Docker ?
• Docker is a software containerization platform
which enable us to run our software in
isolated environment (container).
• Isolated => keep the consistency of our
software dependencies without being worried
to be conflicted with other software in the
same machine.
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Containerization vs Virtualization
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
source: https://docs.docker.com/get-started/#containers-and-virtual-machines
Docker Installation
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
source: https://docs.docker.com/install/
Docker Installation (2)
• Download and Install Docker for desktop:
– Mac :
https://download.docker.com/mac/stable/Docker.dmg
– Windows (using Hyper-V) :
https://download.docker.com/win/stable/Docker%20for%
20Windows%20Installer.exe
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Docker Installation (3)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Enable Hyper-V on Windows:
Docker for Windows need Hyper-V to run
Linux Container.
Docker Installation (4)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Installation on Progress
Wait until the installation
process is finished
Docker Installation (5)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Test Your Docker Installation
Open terminal / powershell and run
`docker version` command to check
whether your Docker is installed
Say Hello To Docker!
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
It’s time to say hello :)
Run `docker run hello-world` from
your terminal / powershell to make
sure your docker is working properly
Dockerize
• Is a process converting your app to run within
a Docker container
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Container Container Container
Code Code
VPS
Typical Web App Stack
• Web Server (NginX)
• Database (MySQL / MariaDB)
• Language (PHP)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Fat Container vs Slim Container
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Container
Code
PRO:
• Straight Forward
• Simple
CONS:
• Huge Size
• Tightly Coupled
Fat Container vs Slim Container (2)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Container
Container
Container
Code
Code
PRO:
• Small Size
• Loosely Coupled
CONS:
• Need some effort to
compose all of
them
Docker Compose
• Compose is a tool for defining and running
multi-container Docker applications. With
Compose, you use a YAML file to configure
your application’s services. Then, with a single
command, you create and start all the services
from your configuration.
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Source: https://docs.docker.com/compose/overview/
Docker Compose (2)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Docker compose definition file:
1. It must be named as `docker-
compose.yml`
2. Consist of 3 sections:
• Services
• Volumes (optional)
• Networks (optional)
3. This is the place where you put all
of your container definition and
linking them together
Dockerize Your App
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
What we need to do:
1. Make sure NginX can read our
“src” folder (index.html)
2. Make sure NginX can execute the
php script (index.php)
3. Make sure NginX can connect to
DB (db_connect.php)
Dockerize Your App (2)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Docker-compose syntax version
Our container name
Docker image that we will use for our
webserver (nginx ver. 1.13)
Expose container port
(80) into host port (80)
Bind “src “ folder in host to
“/usr/share/nginx/html in container
Goal:
Make sure NginX can read our “src”
folder (index.html)
Dockerize Your App (3)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Run `docker-compose up -d` to run our Docker container
Run `docker ps –a` to check our container status
Dockerize Your App (4)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Open web browser and type ‘localhost’ to check our app
Goal: Make sure NginX can read our
“src” folder (index.html) [COMPLETED]
Dockerize Your App (5)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
ContainerContainer
CodeCode
:9000
PHP-FPM
(Fastcgi Process Manager)
Goal: Make sure NginX can
execute the php script
(index.php)
What to do:
1. Bind our source code folder
into PHP Container, so it can
execute our php script file
2. Link nginx and php together
so that nginx can pass the
request into php container
(via port 9000)
Dockerize Your App (6)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
PHP FPM Container definition
Define a network called “network01”
Connect php container into “network01” and
give alias “phpnetwork” so that other container
can “ping” this container using it’s alias (treat this
like a host name)
Dockerize Your App (7)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
NginX Configuration:
1. Create new file called “nginx.conf”
2. When there is a request with “.php” at
the end of url / location, pass the
request into php container
3. We can pass the request into php
container by using it’s alias name
(must connect into the same network)
Dockerize Your App (7)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Bind “nginx.conf” file in host
into “/etc/nginx/conf.d/default.com” in container
Connect webserver container into
“network01” (same as php container)
Update webserver container definition:
Dockerize Your App (8)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Run ‘docker-compose up –d’ again
Open web browser and go to ‘http://localhost/index.php’
to check our app
Goal: Make sure NginX can execute the
php script (index.php) [COMPLETED]
Dockerize Your App (9)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Configure MySQL container using
environment variable
Connect MySQL container into
“network01” (same as php) and give
alias “database”
Bind port “3306” in container into
port “3366” in host / local (you can
connect to MySQL container from
host / local using this port)
Dockerize Your App (10)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Run ‘docker exec –it php /bin/bash’
to go inside php container
Run ‘docker-php-ext-install pdo mysqli’ (inside container) to
install php pdo and mysqli extension.
Dockerize Your App (10)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Build php script to test our database connection
Dockerize Your App (11)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Run ‘docker-compose up –d’ again
Open web browser and go to ‘http://localhost/db_connect.php’
to check our app
Goal: Make sure NginX can connect to
DB (db_connect.php) [COMPLETED]
Dockerize Your App (12)
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Container ContainerContainer
CodeCode
Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
Thank You :)
Salman El Farisi
dev.salman.farisi@gmail.com
salman.farisi@badr-interactive.com
Lead Developer @ PT. Badr Interactive

Mais conteúdo relacionado

Mais procurados

Red Hat OpenShift V3 Overview and Deep Dive
Red Hat OpenShift V3 Overview and Deep DiveRed Hat OpenShift V3 Overview and Deep Dive
Red Hat OpenShift V3 Overview and Deep Dive
Greg Hoelzer
 
Security: The Value of SBOMs
Security: The Value of SBOMsSecurity: The Value of SBOMs
Security: The Value of SBOMs
Weaveworks
 

Mais procurados (20)

DockerDay2015: Deploy Apps on IBM Bluemix
DockerDay2015: Deploy Apps on IBM BluemixDockerDay2015: Deploy Apps on IBM Bluemix
DockerDay2015: Deploy Apps on IBM Bluemix
 
PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...
PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...
PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...
 
FluentD vs. Logstash
FluentD vs. LogstashFluentD vs. Logstash
FluentD vs. Logstash
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with KubernetesThe path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
 
Openshift: Build, deploy & manage open, standard containers
Openshift: Build, deploy & manage open, standard containersOpenshift: Build, deploy & manage open, standard containers
Openshift: Build, deploy & manage open, standard containers
 
OpenShift Application Development | DO288 | Red Hat OpenShift
OpenShift Application Development | DO288 | Red Hat OpenShiftOpenShift Application Development | DO288 | Red Hat OpenShift
OpenShift Application Development | DO288 | Red Hat OpenShift
 
Red Hat OpenShift V3 Overview and Deep Dive
Red Hat OpenShift V3 Overview and Deep DiveRed Hat OpenShift V3 Overview and Deep Dive
Red Hat OpenShift V3 Overview and Deep Dive
 
Application Modernization with PKS / Kubernetes
Application Modernization with PKS / KubernetesApplication Modernization with PKS / Kubernetes
Application Modernization with PKS / Kubernetes
 
DCSF19 Kubernetes Security with OPA
DCSF19 Kubernetes Security with OPA DCSF19 Kubernetes Security with OPA
DCSF19 Kubernetes Security with OPA
 
Introduction to Kubernetes and GKE
Introduction to Kubernetes and GKEIntroduction to Kubernetes and GKE
Introduction to Kubernetes and GKE
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate Everything
 
How we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on KubernetesHow we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on Kubernetes
 
Pragmatic software development in kdb+
Pragmatic software development in kdb+Pragmatic software development in kdb+
Pragmatic software development in kdb+
 
Intro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps WorkshopIntro to Kubernetes & GitOps Workshop
Intro to Kubernetes & GitOps Workshop
 
Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
 
Why observability matters - now and in the future (w/guest Grafana)
Why observability matters - now and in the future (w/guest Grafana)Why observability matters - now and in the future (w/guest Grafana)
Why observability matters - now and in the future (w/guest Grafana)
 
DockerCon 2017: Docker in China
DockerCon 2017: Docker in ChinaDockerCon 2017: Docker in China
DockerCon 2017: Docker in China
 
Security: The Value of SBOMs
Security: The Value of SBOMsSecurity: The Value of SBOMs
Security: The Value of SBOMs
 
DCEU 18: App-in-a-Box with Docker Application Packages
DCEU 18: App-in-a-Box with Docker Application PackagesDCEU 18: App-in-a-Box with Docker Application Packages
DCEU 18: App-in-a-Box with Docker Application Packages
 
Openshift YARN - strata 2014
Openshift YARN - strata 2014Openshift YARN - strata 2014
Openshift YARN - strata 2014
 

Semelhante a Dockerize Your Web Application Stack - Salman El Farisi

Docker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - OverviewDocker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - Overview
Chris Ciborowski
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
QAware GmbH
 

Semelhante a Dockerize Your Web Application Stack - Salman El Farisi (20)

Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_
 
Docker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker SlidesDocker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker Slides
 
Docker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - OverviewDocker Birthday #3 Slides - Overview
Docker Birthday #3 Slides - Overview
 
Docker for dev
Docker for devDocker for dev
Docker for dev
 
Tampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday DockerTampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday Docker
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 
Mythical Mysfits: Monolith to Microservice with Docker and AWS Fargate (CON21...
Mythical Mysfits: Monolith to Microservice with Docker and AWS Fargate (CON21...Mythical Mysfits: Monolith to Microservice with Docker and AWS Fargate (CON21...
Mythical Mysfits: Monolith to Microservice with Docker and AWS Fargate (CON21...
 
Docker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationDocker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - Presentation
 
How to easy deploy app into any cloud
How to easy deploy app into any cloudHow to easy deploy app into any cloud
How to easy deploy app into any cloud
 
Docker Application to Scientific Computing
Docker Application to Scientific ComputingDocker Application to Scientific Computing
Docker Application to Scientific Computing
 
ASP.NET and Docker
ASP.NET and DockerASP.NET and Docker
ASP.NET and Docker
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
 
Docker Container As A Service - Mix-IT 2016
Docker Container As A Service - Mix-IT 2016Docker Container As A Service - Mix-IT 2016
Docker Container As A Service - Mix-IT 2016
 
Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...
Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...
Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...
 
Docker Platform and Ecosystem Nov 2015
Docker Platform and Ecosystem Nov 2015Docker Platform and Ecosystem Nov 2015
Docker Platform and Ecosystem Nov 2015
 
Docker for PHP Developers - Jetbrains
Docker for PHP Developers - JetbrainsDocker for PHP Developers - Jetbrains
Docker for PHP Developers - Jetbrains
 
HPC Cloud Burst Using Docker
HPC Cloud Burst Using DockerHPC Cloud Burst Using Docker
HPC Cloud Burst Using Docker
 
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
 
DockerPenang Meetup #3
DockerPenang Meetup #3DockerPenang Meetup #3
DockerPenang Meetup #3
 
Demystifying Containerization Principles for Data Scientists
Demystifying Containerization Principles for Data ScientistsDemystifying Containerization Principles for Data Scientists
Demystifying Containerization Principles for Data Scientists
 

Mais de DevOpsDaysJKT

Mais de DevOpsDaysJKT (11)

Migrating to Openshift - Reyhan Fabianto
Migrating to Openshift - Reyhan FabiantoMigrating to Openshift - Reyhan Fabianto
Migrating to Openshift - Reyhan Fabianto
 
The Universe as Code - Dave Kerr
The Universe as Code - Dave KerrThe Universe as Code - Dave Kerr
The Universe as Code - Dave Kerr
 
Not a DevOps talk - Coté
Not a DevOps talk - CotéNot a DevOps talk - Coté
Not a DevOps talk - Coté
 
The State Of DevOps 2018 - Matt Ray
The State Of DevOps 2018 - Matt RayThe State Of DevOps 2018 - Matt Ray
The State Of DevOps 2018 - Matt Ray
 
Scrum around the world - Red Tangerine
Scrum around the world - Red TangerineScrum around the world - Red Tangerine
Scrum around the world - Red Tangerine
 
How Honestbee Does CI/CD on Kubernetes - Vincent DeSmet
How Honestbee Does CI/CD on Kubernetes - Vincent DeSmetHow Honestbee Does CI/CD on Kubernetes - Vincent DeSmet
How Honestbee Does CI/CD on Kubernetes - Vincent DeSmet
 
Healthy DevOps - Masto Sitorus
Healthy DevOps - Masto SitorusHealthy DevOps - Masto Sitorus
Healthy DevOps - Masto Sitorus
 
DevOps Practice in Nonprofit - Abdurrachman Mappuji
DevOps Practice in Nonprofit - Abdurrachman MappujiDevOps Practice in Nonprofit - Abdurrachman Mappuji
DevOps Practice in Nonprofit - Abdurrachman Mappuji
 
DevOps Adoption: Challenges & Opportunities
DevOps Adoption: Challenges & OpportunitiesDevOps Adoption: Challenges & Opportunities
DevOps Adoption: Challenges & Opportunities
 
Batch size matter - Thomas Rothe
Batch size matter - Thomas Rothe Batch size matter - Thomas Rothe
Batch size matter - Thomas Rothe
 
DevOpsDays Jakarta Igites
DevOpsDays Jakarta IgitesDevOpsDays Jakarta Igites
DevOpsDays Jakarta Igites
 

Último

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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Dockerize Your Web Application Stack - Salman El Farisi

  • 1. Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Dockerize Your Web Application Stack (PHP, MySQL and NginX) Salman El Farisi dev.salman.farisi@gmail.com salman.farisi@badr-interactive.com Lead Developer @ PT. Badr Interactive
  • 2. What is Docker ? • Docker is a software containerization platform which enable us to run our software in isolated environment (container). • Isolated => keep the consistency of our software dependencies without being worried to be conflicted with other software in the same machine. Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
  • 3. Containerization vs Virtualization Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta source: https://docs.docker.com/get-started/#containers-and-virtual-machines
  • 4. Docker Installation Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta source: https://docs.docker.com/install/
  • 5. Docker Installation (2) • Download and Install Docker for desktop: – Mac : https://download.docker.com/mac/stable/Docker.dmg – Windows (using Hyper-V) : https://download.docker.com/win/stable/Docker%20for% 20Windows%20Installer.exe Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
  • 6. Docker Installation (3) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Enable Hyper-V on Windows: Docker for Windows need Hyper-V to run Linux Container.
  • 7. Docker Installation (4) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Installation on Progress Wait until the installation process is finished
  • 8. Docker Installation (5) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Test Your Docker Installation Open terminal / powershell and run `docker version` command to check whether your Docker is installed
  • 9. Say Hello To Docker! Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta It’s time to say hello :) Run `docker run hello-world` from your terminal / powershell to make sure your docker is working properly
  • 10. Dockerize • Is a process converting your app to run within a Docker container Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Container Container Container Code Code VPS
  • 11. Typical Web App Stack • Web Server (NginX) • Database (MySQL / MariaDB) • Language (PHP) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta
  • 12. Fat Container vs Slim Container Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Container Code PRO: • Straight Forward • Simple CONS: • Huge Size • Tightly Coupled
  • 13. Fat Container vs Slim Container (2) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Container Container Container Code Code PRO: • Small Size • Loosely Coupled CONS: • Need some effort to compose all of them
  • 14. Docker Compose • Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Source: https://docs.docker.com/compose/overview/
  • 15. Docker Compose (2) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Docker compose definition file: 1. It must be named as `docker- compose.yml` 2. Consist of 3 sections: • Services • Volumes (optional) • Networks (optional) 3. This is the place where you put all of your container definition and linking them together
  • 16. Dockerize Your App Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta What we need to do: 1. Make sure NginX can read our “src” folder (index.html) 2. Make sure NginX can execute the php script (index.php) 3. Make sure NginX can connect to DB (db_connect.php)
  • 17. Dockerize Your App (2) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Docker-compose syntax version Our container name Docker image that we will use for our webserver (nginx ver. 1.13) Expose container port (80) into host port (80) Bind “src “ folder in host to “/usr/share/nginx/html in container Goal: Make sure NginX can read our “src” folder (index.html)
  • 18. Dockerize Your App (3) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Run `docker-compose up -d` to run our Docker container Run `docker ps –a` to check our container status
  • 19. Dockerize Your App (4) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Open web browser and type ‘localhost’ to check our app Goal: Make sure NginX can read our “src” folder (index.html) [COMPLETED]
  • 20. Dockerize Your App (5) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta ContainerContainer CodeCode :9000 PHP-FPM (Fastcgi Process Manager) Goal: Make sure NginX can execute the php script (index.php) What to do: 1. Bind our source code folder into PHP Container, so it can execute our php script file 2. Link nginx and php together so that nginx can pass the request into php container (via port 9000)
  • 21. Dockerize Your App (6) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta PHP FPM Container definition Define a network called “network01” Connect php container into “network01” and give alias “phpnetwork” so that other container can “ping” this container using it’s alias (treat this like a host name)
  • 22. Dockerize Your App (7) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta NginX Configuration: 1. Create new file called “nginx.conf” 2. When there is a request with “.php” at the end of url / location, pass the request into php container 3. We can pass the request into php container by using it’s alias name (must connect into the same network)
  • 23. Dockerize Your App (7) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Bind “nginx.conf” file in host into “/etc/nginx/conf.d/default.com” in container Connect webserver container into “network01” (same as php container) Update webserver container definition:
  • 24. Dockerize Your App (8) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Run ‘docker-compose up –d’ again Open web browser and go to ‘http://localhost/index.php’ to check our app Goal: Make sure NginX can execute the php script (index.php) [COMPLETED]
  • 25. Dockerize Your App (9) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Configure MySQL container using environment variable Connect MySQL container into “network01” (same as php) and give alias “database” Bind port “3306” in container into port “3366” in host / local (you can connect to MySQL container from host / local using this port)
  • 26. Dockerize Your App (10) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Run ‘docker exec –it php /bin/bash’ to go inside php container Run ‘docker-php-ext-install pdo mysqli’ (inside container) to install php pdo and mysqli extension.
  • 27. Dockerize Your App (10) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Build php script to test our database connection
  • 28. Dockerize Your App (11) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Run ‘docker-compose up –d’ again Open web browser and go to ‘http://localhost/db_connect.php’ to check our app Goal: Make sure NginX can connect to DB (db_connect.php) [COMPLETED]
  • 29. Dockerize Your App (12) Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Container ContainerContainer CodeCode
  • 30. Thursday, April 26, 2018 DevOpsDays @Menara BTPN, Jakarta Thank You :) Salman El Farisi dev.salman.farisi@gmail.com salman.farisi@badr-interactive.com Lead Developer @ PT. Badr Interactive