Docker - Demo on PHP Application deployment


Published on

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.

Published in: Software, Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Docker - Demo on PHP Application deployment

  1. 1. Introduction to Docker Demo on PHP Application deployment Arun prasath S April, 2014
  2. 2. 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 ChallengeMultiplicityofStacksMultiplicityof hardware environments Production Cluster Customer Data Center Doservicesandapps interact appropriately? CanImigrate smoothlyand quickly?
  3. 3. Static website Web frontendUser DB Queue Analytics DB Development VM QA server Public Cloud Contributor’s laptop Docker is a shipping container system for codeMultiplicityofStacks Multiplicityof hardware environments Production Cluster Customer Data Center Doservicesandapps interact appropriately? CanImigrate smoothlyandquickly …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…
  4. 4. Why Developers Care Build 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
  5. 5. 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
  6. 6. Underlying Technology • Namespaces (pid, net, ipc, mnt, uts) • Control group • UnionFS Containers
  7. 7. App A Containers vs. VMs Hypervisor (Type 2) Host OS Server Guest OS Bins/ Libs App A’ Guest OS Bins/ Libs App B Guest OS Bins/ Libs AppA’ Docker Host OS Server Bins/Libs AppA Bins/Libs AppB AppB’ AppB’ AppB’ VM Container Containers are isolated, but share OS and, where appropriate, bins/libraries Guest OS Guest OS …result is significantly faster deployment, much less overhead, easier migration, faster restart
  8. 8. Why are Docker containers lightweight? Bins/ Libs App A Original App (No OS to take up space, resources, or require restart) AppΔ Bins/ App A Bins/ Libs App A’ Guest OS Bins/ Libs Modified App Union file system allows us to only save the diffs Between container A and container A’ VMs Every app, every copy of an app, and every slight modification of the app requires a new virtual server App A Guest OS Bins/ Libs Copy of App No OS. Can Share bins/libs App A Guest OS Guest OS VMs Containers
  9. 9. What are the basics of the Docker system? Source Code Repository Dockerfile For A Docker Engine Docker Container Image Registry Build Docker Host 2 OS (Linux) ContainerA ContainerB ContainerC ContainerA Push Search Pull Run Host 1 OS (Linux)
  10. 10. Why containers matter Physical 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.
  11. 11. Usecases
  12. 12. 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
  13. 13. Demo quick run : 1) Download this folder or files from Git - 2) 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/bash 4) You can run as many instances you want by running the above command 5) 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 or http://<your-container-ip>:80 (You can view your container ID by docker ps and can view your container IP by docker inspect <container-ID>)
  14. 14. Demo explained Folder structure php-app |______apache2files------apache2.conf | |___ports.conf -> Apache configuration files | |______Dockerfile -> Docker file for building image | |______www/ -> PHP Application folder
  15. 15. Demo explained Dockerfile # Set the base image to Ubuntu FROM ubuntu  Base image RUN apt-get update # File Author / Maintainer MAINTAINER Example Arun RUN 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 build ADD apache2files/ports.conf /etc/apache2/ports.conf # Expose the default port EXPOSE 80 #CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]  These lines are not working, when new instance starts, cant start apache #CMD service apache2 start RUN echo 'service apache2 start ' > /etc/bash.bashrc  Hence I started apache this way , # Set default container command #ENTRYPOINT /bin/bash
  16. 16. 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