Upload
arun-prasath
View
5.087
Download
2
Embed Size (px)
DESCRIPTION
Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more. In this demo, I will show how to build a Apache image from a Dockerfile and deploy a PHP application which is present in an external folder using custom configuration files.
Citation preview
Introduction to Docker Demo on PHP Application deployment
Arun prasath SApril, 2014
Static website
Web frontend
User DB
Queue Analytics DB
Background workers
API endpoint
nginx 1.5 + modsecurity + openssl + bootstrap 2
postgresql + pgv8 + v8
hadoop + hive + thrift + OpenJDK
Ruby + Rails + sass + Unicorn
Redis + redis-sentinel
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs + phantomjs
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client
Development VM
QA server
Public Cloud
Disaster recovery
Contributor’s laptop
Production Servers
The ChallengeM
ultip
licity
of S
tack
sM
ultip
licity
of
hard
war
e en
viro
nmen
ts
Production Cluster
Customer Data Center
Do services and apps
interact appropriately?
Can I migrate
smoothly and quickly?
Static website Web frontend User DB Queue Analytics DB
Development VM QA server Public Cloud
Contributor’s laptop
Docker is a shipping container system for code M
ultip
licity
of S
tack
sM
ultip
licity
of
hard
war
e en
viro
nmen
ts
Production Cluster
Customer Data Center
Do services and apps
interact appropriately?
Can I migrate
smoothly and quickly
…that can be manipulated using standard operations and run consistently on virtually any hardware platform
An engine that enables any payload to be encapsulated as a lightweight, portable, self-sufficient container…
Why Developers CareBuild once…(finally) run anywhere*• A clean, safe, hygienic and portable runtime environment for your app.• No worries about missing dependencies, packages and other pain points during
subsequent deployments.• Run each app in its own isolated container, so you can run various versions of
libraries and other dependencies for each app without worrying• Automate testing, integration, packaging…anything you can script • Reduce/eliminate concerns about compatibility on different platforms, either
your own or your customers. • Cheap, zero-penalty containers to deploy services? A VM without the overhead
of a VM? Instant replay and reset of image snapshots? That’s the power of Docker
Why Devops Cares?
Configure once…run anything• Make the entire lifecycle more efficient, consistent, and repeatable• Increase the quality of code produced by developers. • Eliminate inconsistencies between development, test, production, and
customer environments• Support segregation of duties• Significantly improves the speed and reliability of continuous deployment and
continuous integration systems• Because the containers are so lightweight, address significant performance,
costs, deployment, and portability issues normally associated with VMs
Underlying Technology• Namespaces (pid, net, ipc, mnt, uts)• Control group• UnionFS
Containers
AppA
Containers vs. VMs
Hypervisor (Type 2)
Host OS
Server
GuestOS
Bins/Libs
AppA’
GuestOS
Bins/Libs
AppB
GuestOS
Bins/Libs
App A’
Docker
Host OS
Server
Bins/Libs
App ABins/Libs
App B
App B’
App B’
App B’VM
Container
Containers are isolated,but share OS and, whereappropriate, bins/libraries
GuestOS
GuestOS
…result is significantly faster deployment, much less overhead, easier migration, faster restart
Why are Docker containers lightweight?
Bins/Libs
AppA
Original App(No OS to takeup space, resources,or require restart)
App Δ
Bins/
AppA
Bins/Libs
AppA’
GuestOS
Bins/Libs
Modified App
Union file system allowsus to only save the diffsBetween container A and containerA’
VMsEvery app, every copy of anapp, and every slight modificationof the app requires a new virtual server
AppA
GuestOS
Bins/Libs
Copy ofApp
No OS. Can Share bins/libs
AppA
GuestOS
GuestOS
VMs Containers
What are the basics of the Docker system?
Source Code Repository
DockerfileFor
A
Docker Engine
DockerContainer
Image Registry
Build
Docker
Host 2 OS (Linux)
Container A
Container B
Container C
Container A
Push
Search Pull
Run
Host 1 OS (Linux)
Why containers matterPhysical Containers Docker
Content Agnostic The same container can hold almost any type of cargo
Can encapsulate any payload and its dependencies
Hardware Agnostic Standard shape and interface allow same container to move from ship to train to semi-truck to warehouse to crane without being modified or opened
Using operating system primitives (e.g. LXC) can run consistently on virtually any hardware—VMs, bare metal, openstack, public IAAS, etc.—without modification
Content Isolation and Interaction
No worry about anvils crushing bananas. Containers can be stacked and shipped together
Resource, network, and content isolation. Avoids dependency hell
Automation Standard interfaces make it easy to automate loading, unloading, moving, etc.
Standard operations to run, start, stop, commit, search, etc. Perfect for devops: CI, CD, autoscaling, hybrid clouds
Highly efficient No opening or modification, quick to move between waypoints
Lightweight, virtually no perf or start-up penalty, quick to move and manipulate
Separation of duties Shipper worries about inside of box, carrier worries about outside of box
Developer worries about code. Ops worries about infrastructure.
Usecases
Demo – PHP application deployment
In this demo, I will show how to build a apache image from a Dockerfile and deploy a PHP application which is present in an external folder using custom configuration files.
Requirements:
Linux OS with Docker installed
Demo quick run :
1) Download this folder or files from Git - https://github.com/bingoarunprasath/php-app-docker.git2) Now build a image for app deployment. From the folder downloaded, run the command
docker build -t bingoarunprasath/php .3) Run the image by this command
docker run -i -t -d -p 80 -v /root/php-app/www:/var/www bingoarunprasath/php /bin/bash4) You can run as many instances you want by running the above command5) Run docker ps command to see the launched container. Note down the port number. (in my case 49172)
6) Now you can see your web application by visiting http://<your-host-ip>:49172 orhttp://<your-container-ip>:80
(You can view your container ID by docker ps and can view your container IP by docker inspect <container-ID>)
php-app.rar
Demo explained Folder structure
php-app |______apache2files------apache2.conf | |___ports.conf -> Apache configuration files | |______Dockerfile -> Docker file for building image | |______www/ -> PHP Application folder
Demo explained Dockerfile# Set the base image to UbuntuFROM ubuntu Base imageRUN apt-get update# File Author / MaintainerMAINTAINER Example ArunRUN apt-get install apache2 –y Installed Apache# Copy the configuration files from host ADD apache2files/apache2.conf /etc/apache2/apache2.conf Configuration files are copied during image buildADD apache2files/ports.conf /etc/apache2/ports.conf# Expose the default portEXPOSE 80#CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] These lines are not working, when new instance starts, cant start apache#CMD service apache2 startRUN echo 'service apache2 start ' > /etc/bash.bashrc Hence I started apache this way , # Set default container command#ENTRYPOINT /bin/bash
Demo explained Commands
1) Build image by using the Dockerfile in the current folder
$ docker build -t bingoarunprasath/php-app .
2) Run an instance from image build
$ docker run -i -t -d -p 80 -v /root/php-app/www:/var/www bingoarunprasath/php-app /bin/bash
-v /root/php-app/www:/var/www PHP files are mounted during instance launch, Hence different apps can be mounted using the same image