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

Building Containerized Applications with Docker

Building Containerized Applications with Docker

A high-level introduction to containers, Docker, and how you might use them within an application. Video here: https://www.youtube.com/watch?v=SGyLjrY3LJo

Laura Frank

March 07, 2015
Tweet

More Decks by Laura Frank

Other Decks in Technology

Transcript

  1. A tool for managing containers • Managing code to run

    inside • Executing and running code Docker
  2. • Run in a self-contained execution environment • Share the

    kernel of host system • Are isolated from other containers • Have fast boot times & low overhead Containers
  3. A container is a virtualization layer — sort of like

    a VM — but with some fundamental differences If you deploy your applications in virtual machines, you can instead deploy them in containers.
  4. hardware host OS hypervisor $ guest OS libraries web $

    guest OS $ guest OS libraries DB libraries web
  5. Containers have slightly more complexity but They reduce the amount

    of time/space resources needed to run your application
  6. • It’s fast! • It’s cheap! • It’s portable! •

    It’s safe! Benefits of Containerization
  7. A tool for managing containers • Managing code to run

    inside • Executing and running code Docker
  8. Interacting with the Registry • Push and pull —just like

    GitHub • Two types of images • Services • Project base images
  9. Private Registries • Get image from Docker Registry • Can

    have authentication • Push and pull just like with Docker Hub
  10. A tool for managing containers • Managing code to run

    inside • Executing and running code Docker
  11. • A computer • Application code • Coffee (if you’d

    like) Things you need Installing Docker
  12. Anything else? You need to use a lightweight VM. Pro

    Tip: Boot2Docker (OSX and Windows) Linux? Install Docker with official packages. A Computer
  13. To run your application in a container, you must first

    create an image Application Code All containers are based on images An image is controlled by a Dockerfile
  14. Application Code Two ways to get images: docker pull foo/bar

    or docker run foo/bar 1. Pull down from Docker Hub docker build -t foo/bar . 2. Build from your own Dockerfile
  15. • Available on Docker Hub • Maintained by other people

    (laziness++) • Repositories includes instructions for bootstrapping • Images can be base images or actually run services Application Code: Official Images
  16. Application Code • Static: all files and code are contained

    in image • Dynamic: link folders to modify code (development only)
  17. Application Code • Static: all files and code are contained

    in image • Dynamic: link folders to modify code (development only)
  18. Application Code Using static images from the Docker Hub, you

    can create a containerized application without having to write your own code docker run mysql (…) docker run wordpress (…)
  19. Application Code You can also package your own code and

    run it. docker run mysql (…) docker run my_image (…) docker build -t my_image .
  20. FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> EXPOSE 4567 RUN mkdir

    -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
  21. FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> EXPOSE 4567 RUN mkdir

    -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
  22. FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> EXPOSE 4567 RUN mkdir

    -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This copies code into the container STATIC! Not for apps under active development Great for dependencies and production applications
  23. FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> EXPOSE 4567 RUN mkdir

    -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This makes things happen to your code
  24. FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> EXPOSE 4567 RUN mkdir

    -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile This makes the code happen
  25. Application Templating • Use your own images, or images from

    the Docker Registry • Specify config options beforehand • Run applications with one or two simple commands
  26. --- name: Rails with PostgreSQL description: Rails with PostgreSQL images:

    - category: Web Tier name: Rails source: rheinwein/rails:latest description: Rails App type: Default expose: [] ports: - host_port: '8080' container_port: '3000' links: - service: Database alias: DB_1 environment: [] volumes: []
  27. Docker Hub: registry.hub.docker.com Boot2Docker: boot2docker.io Panamax: panamax.io Rails Girls Summer

    of Code!: railsgirlssummerofcode.org rheinwein/hello-world-container-demo