Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker for PHP Developers

Kapil Sharma
December 10, 2016

Docker for PHP Developers

Slides of PHP Reboot meetup on 'Docker for PHP Developers'.

Kapil Sharma

December 10, 2016
Tweet

More Decks by Kapil Sharma

Other Decks in Technology

Transcript

  1. PHPReboot.com Kapil Sharma What is PHP Reboot? 4 PHP Reboot

    Developers’ community in Pune, India. Started in April 2014. meetup.com/phpreboot & phpreboot.com PHP Reboot magazine PHPReboot.com is open source github.com/phpreboot/website
  2. PHPReboot.com Kapil Sharma About me • Kapil Sharma • Technical

    Architect at Ansh Systems. • Zend certified PHP Engineer with12 Yrs experience in Web app development. • Twitter: kapilsharmainfo • Blog: blog.kapilsharms.info • Slides: speakerdeck.com/ kapilsharma 5
  3. 6

  4. PHPReboot.com Kapil Sharma What we will cover today? 10 Virtualisation

    Vs. Containerization Why is Docker? Docker Architecture
  5. PHPReboot.com Kapil Sharma What we will cover today? 11 Virtualisation

    Vs. Containerization Why is Docker? Docker Architecture Hands on. Setting PHP Environment
  6. PHPReboot.com Kapil Sharma Virtualization • Advantages • Multiple OS •

    Easy Maintenance • Low cost 13 Host OS CPU RAM HD Network Hypervisor Guest OS Guest OS Guest OS Bins & Libs Bins & Libs Bins & Libs App1 App2 App3 • Disadvantages • Performance • Guest OS not as effective as Host OS • Long boot-up process
  7. PHPReboot.com Kapil Sharma Containerization • Advantages over Virtualisation • Containers

    use Kernel of host OS. • Lighter • Smaller 14 Host OS CPU RAM HD Network Container Engine Bins & Libs Bins & Libs Bins & Libs App1 App2 App3 Note: Containerisation is just Virtualization at the OS level.
  8. PHPReboot.com Kapil Sharma Installing docker 17 Docker use linux kernel

    of host OS Mac OS X - Docker for Mac - Docker Toolbox Windows - Docker for Windows - Docker Toolbox Linux - Supports natively, without any other layer.
  9. PHPReboot.com Kapil Sharma Most used commands 20 docker pull <image-name:tag>

    Pull image from registry. Tag is the version of image. docker run <image-name:tag> Runs an image. docker run <image-id> docker images List all images. docker ps List all running containers. docker ps -a List all containers. docker start <container-id> docker stop <container-id> docker rm <container-name> docker rmi <image-id> docker mi <repo:tag>
  10. PHPReboot.com Kapil Sharma Docker run 21 docker run [options] image

    [command] [arguments] Common options: --rm - Remove the container once it is done. -i - run interactive mode. -t - run tty. -d - run in background. --name <name> - to give name to the container. -p <local port>:<container port> - port forwarding. docker exec -ti <container name> bash docker run -d -name web1 -p 8080:80 nginx
  11. PHPReboot.com Kapil Sharma Docker build - creating image 23 Lets

    make apache image & run a simple site. docker test |- Dockerfile |- apache-config.conf `- www/index.php
  12. PHPReboot.com Kapil Sharma Docker file From ubuntu:latest MAINTAINER Kapil Sharma

    <[email protected]> RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl RUN a2enmod php7.0 RUN a2enmod rewrite RUN sed -i “s/short_open_tab = Off/short_open_tag = On" / etc/php/7.0/apache2/php.ini
  13. PHPReboot.com Kapil Sharma ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV

    APACHE_LOG_DIR /var/log/apache2 ENV APACHE_LOCK_DIR /var/lock/apache2 ENV APACHE_PID_FILE /var/run/apache.pid EXPOSE 80 ADD www /var/www/site ADD apache-config.conf /etc/apache2/sites-enabled/000- default.conf CMD /use/bin/apache2ctl -D FOREGROUND
  14. PHPReboot.com Kapil Sharma Run 27 docker run -p 8080:80 -d

    -v /Users/kapilsharma/dockertest/www:/var/www/site testsite
  15. PHPReboot.com Kapil Sharma Going forward 29 We just touched docker

    at very high level There are lot many possibilities with docker Now you know the basics, please go ahead and try yourself.