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

Containers and Docker - Leeds Technology UG

Containers and Docker - Leeds Technology UG

Matt Saunders

October 22, 2015
Tweet

More Decks by Matt Saunders

Other Decks in Technology

Transcript

  1. In the Beginning • We bought a server • We

    did manual installations • They were long-lived • Scaling them out took weeks or months
  2. Virtualisation • Slow to spin up instances • Hard to

    scale on-demand • Lots of waste • Isolation Overkill
  3. Containers • Containers are isolated from each other • Segregated

    using • linux namespaces • control groups (cgroups)
  4. cgroups • “cgroups (abbreviated from control groups) is a Linux

    kernel feature that limits, accounts for and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.”
  5. Namespaces • “A namespace wraps a global system resource in

    an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource. Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other processes. One use of namespaces is to implement containers.”
  6. Docker Design • An API for working with containers •

    A tool for packaging apps and their dependencies • A tool for moving, storing and managing the lifecycle of containers
  7. Separation of Concerns • “Dave the Developer” • Inside my

    container: • My code • My libraries • My package management • My data
  8. Separation of Concerns • “Olivia from Ops” • Outside the

    container: • Logging • Remote Access • Monitoring • Network Configuration
  9. Docker on Windows and Mac • Docker server only runs

    on Linux • Kernel 3.8 and above • RHEL 7, CentOS 7, Ubuntu 14.04, Debian 7 • Docker client will run on multiple OSes • Statically compiled binaries • boot2docker cheats
  10. Docker Images • mattsbookpro:~ matts$ docker images • REPOSITORY TAG

    IMAGE ID CREATED VIRTUAL SIZE • ubuntu latest 6d4946999d4f 3 weeks ago 188.3 MB • hello-world latest 91c95931e552 11 weeks ago 910 B
  11. Docker Hub • Centralised registry of images • Public and

    private • Signed public images from various vendors
  12. Node package file mattsbookpro:node matts$ cat package.json { "name": "helloexpress",

    "private": true, "version": "0.0.1", "description": "Hello from Express.JS", "author": "Matt Saunders <[email protected]>", "dependencies": { "express": "3.20.3" } }
  13. node index.js file mattsbookpro:node matts$ cat index.js var express =

    require('express'); var PORT = 8080; var app = express(); app.get('/', function (req, res) { res.send('Hello from Express!\n'); }); app.listen(PORT); console.log('Running on http://localhost:' + PORT);
  14. Dockerfile FROM node COPY . /src RUN cd /src ;

    npm install EXPOSE 8080 CMD ["node", "/src/index.js"]
  15. Run it • docker run -d -p 8080:8080 cm6051/helloexpress $

    curl http://192.168.59.104:8080/ Hello from Express!
  16. Docker Volumes • Volumes • Mount directories from the host

    into your container • Add configuration • Extract logs
  17. Docker Ports • Expose ports from your application • Only

    the ones you want to • Route traffic from outside
  18. Use Cases • Continuous Integration • A self-contained env behind

    your CI • Test changes on an always-fresh environment
  19. Use Cases • Blue/Green Deployment • Run full stack on

    fewer servers • Cut between environments atomically
  20. It’s No Free Lunch • Heavy preference for access by

    HTTP(S) • Requires 12 factor apps • Data storage needs extra care • Immutable by design