SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
Walid Ashraf
Researcher , Software Developer, Instructor
about.me/WalidAshraf
DOCKERIZNG WEB
APPLICATIONS
Docker - Walid Ashraf
Table of Contents
Docker File Basics
Creating a NodeJS application
Creating a python application
Docker file acts as the source code for your
image where you specify all the needed tools,
data, code to run you image correctly in any
environment.
DOCKER FILE BASICS
Docker - Walid Ashraf
Docker file basics
From:
• Base Image
• Usage
• FROM <image>
Maintainer
• Who is the Image creator
• Usage
• MAINTAINER <Name>
WORKDIR
• Sets the start directory for the container where the run and the CMD instructions are executed.
• Usage
• WORKDIR /path/to/workdir
RUN
• The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.The resulting committed image will be
used for the next step in the Dockerfile.
• Usage
• RUN <command> (the command is run in a shell - /bin/sh -c - shell form)
• RUN ["executable", "param1", "param2"] (exec form)
Docker - Walid Ashraf
Docker file basics
CMD
• The CMD Command is used as a default entry point to container.And if more than one is added the last one only will take effect
• Usage
• CMD ["executable","param1","param2"] (exec form, this is the preferred form)
• CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
• CMD command param1 param2 (shell form)
COPY
• Copies files from the host file system to the image file system.
• Usage
• COPY <src>... <dest>
• COPY ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
ADD
• The add file is similar to the copy but can handle both tar files and remote URLs
• Usage
• ADD <src>... <dest>
• ADD ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
ENV
• Sets some environment variables for the container
• Usage
• ENV <key> <value> only one perline
• ENV <key>=<value> ... allows multiple per line
Docker - Walid Ashraf
Docker file basics
EXPOSE
• This allows the container ports to be accessed from the global ports. Note that Port
mapping has to be specified directly at creation time using the –p or –P commands
• Usage
• EXPOSE <port> [<port>...]
Vloume
• TheVOLUME instruction creates a mount point with the specified name and marks it
as holding externally mounted volumes from native host or other containers.
• Usage
• VOLUME ["/data"]
Docker - Walid Ashraf
Docker File Best Practices
Don’t add unnecessary files or libraries
Utilize the ecosystem and don't reinvent images
For more ideas and best practices check:
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
http://www.walidashraf.com/2015/10/docker-and-solid-princple.html
Create an application folder (node-app)
CREATING NODEJS
APPLICATION
Docker - Walid Ashraf
Step 1: Create package.json file
{
"name": "docker-ubuntu-hello",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello world app using docker",
"author": "Yourname<Mail@Mail.com>",
"dependencies": {
"express": "3.2.4"
}
}
Docker - Walid Ashraf
Step 2: Create Index.JS File
var express = require('express');
// Constants
var PORT = 8080;
// App
var app = express();
app.get('/', function (req, res) {
res.send('Hello Docker Cairo Geeks :D n');
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);
Docker - Walid Ashraf
Step 3: Create A DockerFile
# Aminimal alpine node image
FROM mhart/alpine-node
# Get The Code
COPY . /src
# Install app dependencies
RUN cd /src; npm install
#Expose a port
EXPOSE 8080
#The Container Start command
CMD ["node", "/src/index.js"]
Docker - Walid Ashraf
& the rest is history
Step 4: Build The Image from Docker File
$ sudo docker build -t washraf/nodeapp .
Step 5: Run the Docker Image
$ sudo docker run -p 1234:8080 –d --name nodeApplication washraf/nodeapp
Docker - Walid Ashraf
Other: Install form GitHub
The Repo:
https://github.com/washraf/docker-meetup
Install git:
apt-get install git
Get the Code:
git clone https://github.com/washraf/docker-meetup
Go to node-app
cd docker-meetup/node-app
Build the image
docker build - t name/app-name .
run the container
docker run -d -p 1234:8080 name/app-name
Docker - Walid Ashraf
The result
Create an application folder (flask-app)
CREATE A PYTHON
APPLICATION
Docker - Walid Ashraf
Step 1: Create File app.py
from flask import Flask, render_template
import random
app = Flask(__name__)
# list of cat images
images = [
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26388-1381844103-11.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr01/15/9/anigif_enhanced-buzz-31540-1381844535-8.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26390-1381844163-18.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-1376-1381846217-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3391-1381844336-26.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-29111-1381845968-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3409-1381844582-13.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr02/15/9/anigif_enhanced-buzz-19667-1381844937-10.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26358-1381845043-13.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-18774-1381844645-6.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-25158-1381844793-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/10/anigif_enhanced-buzz-11980-1381846269-1.gif"
]
@app.route('/')
def index():
url = random.choice(images)
return render_template('index.html', url=url)
if __name__ == "__main__":
app.run(host="0.0.0.0")
Docker - Walid Ashraf
Step 2: Create requirements.txt
Flask==0.10.1
Docker - Walid Ashraf
Step 3: Create templates/index.html
<html>
<head>
<style type="text/css">
body {
background: black; color: white;
}
div.container { max-width: 500px; margin: 100px auto; border: 20px solid white; padding: 10px; text-align: center; }
h4 {
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="container">
<h4>Cat Gif of the day</h4>
<img src="{{url}}" />
<p>
<small>Courtesy: <a href="http://www.buzzfeed.com/copyranter/the-best-cat-gif-post-in-the-history-of-cat-gifs">Buzzfeed</a></small></p>
</div>
</body>
</html>
Docker - Walid Ashraf
Step 4: Create Docker file
# our base image
FROM alpine:latest
# Install python and pip
RUN apk add --update py-pip
# install Python modules needed by the Python app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
# copy files required for the app to run
COPY app.py /usr/src/app/
COPY templates/index.html /usr/src/app/templates/
# tell the port number the container should expose
EXPOSE 5000
# run the application
CMD ["python", "/usr/src/app/app.py"]
Docker - Walid Ashraf
& the rest is history
Step 5:
docker build -t washraf/flask-app .
Step 6:
docker run -p 8888:5000 -d --name flaskApplication washraf/flask-app
Docker - Walid Ashraf
The result
Docker - Walid Ashraf22

Contenu connexe

Tendances

Docker Security Overview
Docker Security OverviewDocker Security Overview
Docker Security OverviewSreenivas Makam
 
Docker 101 - Intro to Docker
Docker 101 - Intro to DockerDocker 101 - Intro to Docker
Docker 101 - Intro to DockerAdrian Otto
 
Docker security introduction-task-2016
Docker security introduction-task-2016Docker security introduction-task-2016
Docker security introduction-task-2016Ricardo Gerardi
 
Docker for developers
Docker for developersDocker for developers
Docker for developersandrzejsydor
 
Docker Mentorweek beginner workshop notes
Docker Mentorweek beginner workshop notesDocker Mentorweek beginner workshop notes
Docker Mentorweek beginner workshop notesSreenivas Makam
 
Docker Security Paradigm
Docker Security ParadigmDocker Security Paradigm
Docker Security ParadigmAnis LARGUEM
 
Docker Security in Production Overview
Docker Security in Production OverviewDocker Security in Production Overview
Docker Security in Production OverviewDelve Labs
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshopRuncy Oommen
 
Docker Security Deep Dive by Ying Li and David Lawrence
Docker Security Deep Dive by Ying Li and David LawrenceDocker Security Deep Dive by Ying Li and David Lawrence
Docker Security Deep Dive by Ying Li and David LawrenceDocker, Inc.
 
Docker 1.11 Presentation
Docker 1.11 PresentationDocker 1.11 Presentation
Docker 1.11 PresentationSreenivas Makam
 
Intro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsIntro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsThomas Chacko
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeDanielle Madeley
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to dockerInstruqt
 
Docker 101 2015-05-28
Docker 101 2015-05-28Docker 101 2015-05-28
Docker 101 2015-05-28Adrian Otto
 
Docker & JVM: A Perfect Match
Docker & JVM: A Perfect MatchDocker & JVM: A Perfect Match
Docker & JVM: A Perfect MatchMatthias Grüter
 
Docker - The Linux Container
Docker - The Linux ContainerDocker - The Linux Container
Docker - The Linux ContainerBalaji Rajan
 

Tendances (20)

Docker Security Overview
Docker Security OverviewDocker Security Overview
Docker Security Overview
 
Docker 101 - Intro to Docker
Docker 101 - Intro to DockerDocker 101 - Intro to Docker
Docker 101 - Intro to Docker
 
Docker security introduction-task-2016
Docker security introduction-task-2016Docker security introduction-task-2016
Docker security introduction-task-2016
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Docker Mentorweek beginner workshop notes
Docker Mentorweek beginner workshop notesDocker Mentorweek beginner workshop notes
Docker Mentorweek beginner workshop notes
 
Docker Security Paradigm
Docker Security ParadigmDocker Security Paradigm
Docker Security Paradigm
 
Docker Security in Production Overview
Docker Security in Production OverviewDocker Security in Production Overview
Docker Security in Production Overview
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshop
 
Docker Security Deep Dive by Ying Li and David Lawrence
Docker Security Deep Dive by Ying Li and David LawrenceDocker Security Deep Dive by Ying Li and David Lawrence
Docker Security Deep Dive by Ying Li and David Lawrence
 
Docker 1.11 Presentation
Docker 1.11 PresentationDocker 1.11 Presentation
Docker 1.11 Presentation
 
The state of the swarm
The state of the swarmThe state of the swarm
The state of the swarm
 
Intro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsIntro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and Windows
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker 101 2015-05-28
Docker 101 2015-05-28Docker 101 2015-05-28
Docker 101 2015-05-28
 
The Power of Docker
The Power of DockerThe Power of Docker
The Power of Docker
 
Docker & JVM: A Perfect Match
Docker & JVM: A Perfect MatchDocker & JVM: A Perfect Match
Docker & JVM: A Perfect Match
 
Docker - The Linux Container
Docker - The Linux ContainerDocker - The Linux Container
Docker - The Linux Container
 
Docker
DockerDocker
Docker
 
Docker orchestration
Docker orchestrationDocker orchestration
Docker orchestration
 

En vedette

revVANITIES lobby presentation 121913ewd
revVANITIES lobby presentation 121913ewdrevVANITIES lobby presentation 121913ewd
revVANITIES lobby presentation 121913ewdEllen Wilson Dilks
 
Be An Exceptional Manager with NLP - ekLeader
Be An Exceptional Manager with NLP - ekLeaderBe An Exceptional Manager with NLP - ekLeader
Be An Exceptional Manager with NLP - ekLeaderekLeader Admin
 
GWAVACon 2015: GWAVA - Up in the Air
GWAVACon 2015: GWAVA - Up in the Air GWAVACon 2015: GWAVA - Up in the Air
GWAVACon 2015: GWAVA - Up in the Air GWAVA
 
Integrating group wise and vibe d_rimser
Integrating group wise and vibe d_rimserIntegrating group wise and vibe d_rimser
Integrating group wise and vibe d_rimserGWAVA
 
Procurement Executive Circle PA & Utilities 2015 - Gustavo Piga
Procurement Executive Circle PA & Utilities 2015 - Gustavo PigaProcurement Executive Circle PA & Utilities 2015 - Gustavo Piga
Procurement Executive Circle PA & Utilities 2015 - Gustavo Pigai-Faber S.p.A.
 
Technical consultant 1 page
Technical consultant 1 pageTechnical consultant 1 page
Technical consultant 1 pageClark Fourie
 
Gwava Cloud Offering
Gwava Cloud OfferingGwava Cloud Offering
Gwava Cloud OfferingGWAVA
 
PEC CORPORATE 2015 - Roberta marracino
PEC CORPORATE 2015 - Roberta marracinoPEC CORPORATE 2015 - Roberta marracino
PEC CORPORATE 2015 - Roberta marracinoi-Faber S.p.A.
 
Quick Start Challenge - Universal App
Quick Start Challenge - Universal AppQuick Start Challenge - Universal App
Quick Start Challenge - Universal AppSudarsan Balaji
 
Androidアプリ開発にクリーンアーキテクチャを取り入れよう (OSS編)
Androidアプリ開発にクリーンアーキテクチャを取り入れよう(OSS編)Androidアプリ開発にクリーンアーキテクチャを取り入れよう(OSS編)
Androidアプリ開発にクリーンアーキテクチャを取り入れよう (OSS編)kan-notice
 
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...GWAVA
 
Windows 10 - tools-tools-tools
Windows 10 - tools-tools-toolsWindows 10 - tools-tools-tools
Windows 10 - tools-tools-toolsRoel van Bueren
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with DockerHanoiJUG
 

En vedette (16)

revVANITIES lobby presentation 121913ewd
revVANITIES lobby presentation 121913ewdrevVANITIES lobby presentation 121913ewd
revVANITIES lobby presentation 121913ewd
 
Be An Exceptional Manager with NLP - ekLeader
Be An Exceptional Manager with NLP - ekLeaderBe An Exceptional Manager with NLP - ekLeader
Be An Exceptional Manager with NLP - ekLeader
 
GWAVACon 2015: GWAVA - Up in the Air
GWAVACon 2015: GWAVA - Up in the Air GWAVACon 2015: GWAVA - Up in the Air
GWAVACon 2015: GWAVA - Up in the Air
 
Integrating group wise and vibe d_rimser
Integrating group wise and vibe d_rimserIntegrating group wise and vibe d_rimser
Integrating group wise and vibe d_rimser
 
Procurement Executive Circle PA & Utilities 2015 - Gustavo Piga
Procurement Executive Circle PA & Utilities 2015 - Gustavo PigaProcurement Executive Circle PA & Utilities 2015 - Gustavo Piga
Procurement Executive Circle PA & Utilities 2015 - Gustavo Piga
 
Technical consultant 1 page
Technical consultant 1 pageTechnical consultant 1 page
Technical consultant 1 page
 
Gwava Cloud Offering
Gwava Cloud OfferingGwava Cloud Offering
Gwava Cloud Offering
 
PEC CORPORATE 2015 - Roberta marracino
PEC CORPORATE 2015 - Roberta marracinoPEC CORPORATE 2015 - Roberta marracino
PEC CORPORATE 2015 - Roberta marracino
 
Formato proyectos de aula1
Formato proyectos de aula1Formato proyectos de aula1
Formato proyectos de aula1
 
113495978_3.PPTX
113495978_3.PPTX113495978_3.PPTX
113495978_3.PPTX
 
Quick Start Challenge - Universal App
Quick Start Challenge - Universal AppQuick Start Challenge - Universal App
Quick Start Challenge - Universal App
 
Androidアプリ開発にクリーンアーキテクチャを取り入れよう (OSS編)
Androidアプリ開発にクリーンアーキテクチャを取り入れよう(OSS編)Androidアプリ開発にクリーンアーキテクチャを取り入れよう(OSS編)
Androidアプリ開発にクリーンアーキテクチャを取り入れよう (OSS編)
 
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...
Micro Focus Keynote: Vision 2020: The Future of Infrastructure Software and M...
 
Windows 10 - tools-tools-tools
Windows 10 - tools-tools-toolsWindows 10 - tools-tools-tools
Windows 10 - tools-tools-tools
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
 
Minna Salmi (THL): Politiikkatoimet ja lapsiperheet
Minna Salmi (THL): Politiikkatoimet ja lapsiperheetMinna Salmi (THL): Politiikkatoimet ja lapsiperheet
Minna Salmi (THL): Politiikkatoimet ja lapsiperheet
 

Similaire à dockerizing web application

Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerGuido Schmutz
 
Docker use dockerfile
Docker use dockerfileDocker use dockerfile
Docker use dockerfilecawamata
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z javaandrzejsydor
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerKuan Yen Heng
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 augVincent De Smet
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with dockerMichelle Liu
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Alessandro Mignogna
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s LifeGlobalLogic Ukraine
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandPRIYADARSHINI ANAND
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Ben Hall
 
Docker DANS workshop
Docker DANS workshopDocker DANS workshop
Docker DANS workshopvty
 

Similaire à dockerizing web application (20)

Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker Container
 
Docker use dockerfile
Docker use dockerfileDocker use dockerfile
Docker use dockerfile
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
Docker, but what it is?
Docker, but what it is?Docker, but what it is?
Docker, but what it is?
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z java
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with docker
 
Docking with Docker
Docking with DockerDocking with Docker
Docking with Docker
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021
 
Docker presentation
Docker presentationDocker presentation
Docker presentation
 
Docker @ Atlogys
Docker @ AtlogysDocker @ Atlogys
Docker @ Atlogys
 
moscmy2016: Extending Docker
moscmy2016: Extending Dockermoscmy2016: Extending Docker
moscmy2016: Extending Docker
 
Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini Anand
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
 
Docker DANS workshop
Docker DANS workshopDocker DANS workshop
Docker DANS workshop
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

dockerizing web application

  • 1. Walid Ashraf Researcher , Software Developer, Instructor about.me/WalidAshraf DOCKERIZNG WEB APPLICATIONS
  • 2. Docker - Walid Ashraf Table of Contents Docker File Basics Creating a NodeJS application Creating a python application
  • 3. Docker file acts as the source code for your image where you specify all the needed tools, data, code to run you image correctly in any environment. DOCKER FILE BASICS
  • 4. Docker - Walid Ashraf Docker file basics From: • Base Image • Usage • FROM <image> Maintainer • Who is the Image creator • Usage • MAINTAINER <Name> WORKDIR • Sets the start directory for the container where the run and the CMD instructions are executed. • Usage • WORKDIR /path/to/workdir RUN • The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.The resulting committed image will be used for the next step in the Dockerfile. • Usage • RUN <command> (the command is run in a shell - /bin/sh -c - shell form) • RUN ["executable", "param1", "param2"] (exec form)
  • 5. Docker - Walid Ashraf Docker file basics CMD • The CMD Command is used as a default entry point to container.And if more than one is added the last one only will take effect • Usage • CMD ["executable","param1","param2"] (exec form, this is the preferred form) • CMD ["param1","param2"] (as default parameters to ENTRYPOINT) • CMD command param1 param2 (shell form) COPY • Copies files from the host file system to the image file system. • Usage • COPY <src>... <dest> • COPY ["<src>",... "<dest>"] (this form is required for paths containing whitespace) ADD • The add file is similar to the copy but can handle both tar files and remote URLs • Usage • ADD <src>... <dest> • ADD ["<src>",... "<dest>"] (this form is required for paths containing whitespace) ENV • Sets some environment variables for the container • Usage • ENV <key> <value> only one perline • ENV <key>=<value> ... allows multiple per line
  • 6. Docker - Walid Ashraf Docker file basics EXPOSE • This allows the container ports to be accessed from the global ports. Note that Port mapping has to be specified directly at creation time using the –p or –P commands • Usage • EXPOSE <port> [<port>...] Vloume • TheVOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. • Usage • VOLUME ["/data"]
  • 7. Docker - Walid Ashraf Docker File Best Practices Don’t add unnecessary files or libraries Utilize the ecosystem and don't reinvent images For more ideas and best practices check: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ http://www.walidashraf.com/2015/10/docker-and-solid-princple.html
  • 8. Create an application folder (node-app) CREATING NODEJS APPLICATION
  • 9. Docker - Walid Ashraf Step 1: Create package.json file { "name": "docker-ubuntu-hello", "private": true, "version": "0.0.1", "description": "Node.js Hello world app using docker", "author": "Yourname<Mail@Mail.com>", "dependencies": { "express": "3.2.4" } }
  • 10. Docker - Walid Ashraf Step 2: Create Index.JS File var express = require('express'); // Constants var PORT = 8080; // App var app = express(); app.get('/', function (req, res) { res.send('Hello Docker Cairo Geeks :D n'); }); app.listen(PORT); console.log('Running on http://localhost:' + PORT);
  • 11. Docker - Walid Ashraf Step 3: Create A DockerFile # Aminimal alpine node image FROM mhart/alpine-node # Get The Code COPY . /src # Install app dependencies RUN cd /src; npm install #Expose a port EXPOSE 8080 #The Container Start command CMD ["node", "/src/index.js"]
  • 12. Docker - Walid Ashraf & the rest is history Step 4: Build The Image from Docker File $ sudo docker build -t washraf/nodeapp . Step 5: Run the Docker Image $ sudo docker run -p 1234:8080 –d --name nodeApplication washraf/nodeapp
  • 13. Docker - Walid Ashraf Other: Install form GitHub The Repo: https://github.com/washraf/docker-meetup Install git: apt-get install git Get the Code: git clone https://github.com/washraf/docker-meetup Go to node-app cd docker-meetup/node-app Build the image docker build - t name/app-name . run the container docker run -d -p 1234:8080 name/app-name
  • 14. Docker - Walid Ashraf The result
  • 15. Create an application folder (flask-app) CREATE A PYTHON APPLICATION
  • 16. Docker - Walid Ashraf Step 1: Create File app.py from flask import Flask, render_template import random app = Flask(__name__) # list of cat images images = [ "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26388-1381844103-11.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr01/15/9/anigif_enhanced-buzz-31540-1381844535-8.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26390-1381844163-18.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-1376-1381846217-0.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3391-1381844336-26.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-29111-1381845968-0.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3409-1381844582-13.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr02/15/9/anigif_enhanced-buzz-19667-1381844937-10.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26358-1381845043-13.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-18774-1381844645-6.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-25158-1381844793-0.gif", "http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/10/anigif_enhanced-buzz-11980-1381846269-1.gif" ] @app.route('/') def index(): url = random.choice(images) return render_template('index.html', url=url) if __name__ == "__main__": app.run(host="0.0.0.0")
  • 17. Docker - Walid Ashraf Step 2: Create requirements.txt Flask==0.10.1
  • 18. Docker - Walid Ashraf Step 3: Create templates/index.html <html> <head> <style type="text/css"> body { background: black; color: white; } div.container { max-width: 500px; margin: 100px auto; border: 20px solid white; padding: 10px; text-align: center; } h4 { text-transform: uppercase; } </style> </head> <body> <div class="container"> <h4>Cat Gif of the day</h4> <img src="{{url}}" /> <p> <small>Courtesy: <a href="http://www.buzzfeed.com/copyranter/the-best-cat-gif-post-in-the-history-of-cat-gifs">Buzzfeed</a></small></p> </div> </body> </html>
  • 19. Docker - Walid Ashraf Step 4: Create Docker file # our base image FROM alpine:latest # Install python and pip RUN apk add --update py-pip # install Python modules needed by the Python app COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt # copy files required for the app to run COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ # tell the port number the container should expose EXPOSE 5000 # run the application CMD ["python", "/usr/src/app/app.py"]
  • 20. Docker - Walid Ashraf & the rest is history Step 5: docker build -t washraf/flask-app . Step 6: docker run -p 8888:5000 -d --name flaskApplication washraf/flask-app
  • 21. Docker - Walid Ashraf The result
  • 22. Docker - Walid Ashraf22