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

Docker Swarm - Atlanta PHP

Docker Swarm - Atlanta PHP

Shawn Stratton

August 04, 2016
Tweet

More Decks by Shawn Stratton

Other Decks in Technology

Transcript

  1. What are Containers?  NOT Virtual Machines.  Sandboxed Processes

    that bundle their configuration, code, and dependencies.  Operating system libraries are dependencies.  Runtimes are dependencies.
  2. What is Docker  Framework around managing Containers  Library

    of “stuff” to make life easier (Docker-Compose, Docker- Machine, Swarm Mode)
  3. Traditional Ops & SDLC  More control for developers, less

    need for environmental setup by a different group (DevOps, SRE, Sysadmin, etc)  Environmental Consistency from local development to production, regardless of what Operating System developer x is using.  Configuration is traditionally managed by environmental variables, allows a immutable build to pass from development to production.
  4. Dependency Management  Each project has its own copies of

    its dependencies.  Dependencies can vary from project to project without interfering / causing unintended consequences.  Operational team doesn’t have to figure out multiple versions of PHP, Node, etc for building or hosting.
  5. Docker Toolbox vs. Docker for *  Docker Toolbox uses

    VirtualBox (by default, can use HyperV, VMWare, etc)  Use docker quickstart or create your own VM with docker- machine create  All of the exposed ports of Docker Containers will be reachable via docker-machine ip <vmname>  Requires some env variables specifically you need to source docker-machine env <vmname>  Works with the built-in virtualization toolset (hyperv on Win10, xhyve on Mac).  Requires Admin rights.  Min. requirement Win10 Pro or OSX Yosemite (10.10).  Exposes ports on Localhost.  Docker cli just works.
  6. Installing Docker Toolbox  Download and install https://www.docker.com/products/docker- toolbox 

    docker-machine create default  source docker-machine env default  Works on both windows (powershell and cmd) and mac (bash).  Edit host file and add:  <docker-machine ip> yourlocaldev.site.com
  7. Installing Docker Beta  Download and install https://www.docker.com/products/docker#/mac https://www.docker.com/products/docker#/windows 

    Run docker app (will create an icon in the system tray, you can configure vm specs there)  Works on both windows (powershell and cmd) and mac (bash).  Edit host file and add:  127.0.0.1 yourlocaldev.site.com
  8.  Images  An image is an inert, immutable, file

    that's essentially a snapshot of a container.  Think of a Class  Container  A runtime instance of an image.  Think of an object.
  9. Image building instructions  FROM – (extends) this defines the

    base image  MAINTAINER – your name.  RUN – execute something on the container  COPY / ADD – copy something to the container  ENV – set an environmental variable  WORKDIR – Set the working directory (where stuff gets executed)  CMD – The command a container executes when it’s started.  ENTRYPOINT – Like CMD but different  EXPOSE – Show a port to your network  More: https://docs.docker.com/engine/reference/builder/
  10. What are the “Docker Commands”  Docker  Interaction with

    the engine (start/stop containers, build images, etc, Swarm is buried here)  docker-machine  Wrapper around virtual machines for Windows/Mac so we can run docker locally.  docker-compose  Helper that works with “compose files” to define an entire stack.
  11. Working with Images  docker images (lists local)  docker

    search (searches images on Docker Hub)  docker pull <image-id/image-name><:optional-tag e.g. latest 5.3 alpine>  docker build –t <tag-name> <directory>  docker push <tag-name>
  12. Running containers  docker run -it --rm -v $(pwd):/app composer/composer

    install  docker run -d <image-id/image-name> (command)  docker ps  docker attach <container-id>  docker exec –it <container-id> <command>  docker logs <container-id>  docker exec –it <container-id> bash
  13.  docker-compose up –d  docker-compose down  docker-compose logs

    –f  docker-compose scale <service name=numberofnodes>
  14. Schedulers  Cluster Managers, determine where on the cluster to

    place containers.  Also handles traffic routing (via exposed ports).  Vary in functionality.  Kubernetes (k8s)  Rancher.io  Nomad  Docker Datacenter  Mesos  ECS SWARM
  15. What are Docker Services?  Definition of runtime containers that

    are to be run on the swarm cluster.  Can specify mounts, images, tags, names, hostname, environmental variables, update strategy ……………………  Can be really simple too.
  16. What else does Swarm offer?  Built in Service Discovery:

    Host for loadbalanced endpoint is the service name. i.e. Redis  Mesh Routing: if I expose port 80 on one node, port 80 is available across the swarm cluster.  Failure Detection: container fails a health check, it’s bounced; worker becomes unavailable, swarm reschedules its containers on other nodes.  Resource Allocation: Can define dedicated memory/cpu per container.