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

Containerized Applications with Docker

Containerized Applications with Docker

An introduction to developing applications with Docker. Given at Ancient City Ruby 2015

Laura Frank

March 26, 2015
Tweet

More Decks by Laura Frank

Other Decks in Technology

Transcript

  1. +

  2. Containerization: What even is it? How do I use Docker

    within my applications? How can I use Docker with Ruby? Three Questions
  3. • 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
  4. A container is a virtualization layer — sort of like

    a VM — but with some fundamental differences Containers can work in conjunction with or in place of virtual machines (VMs).
  5. hardware host OS hypervisor $ guest OS libraries web $

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

    of time/space resources needed to run your application
  7. Anything else? You need to use a lightweight VM. Pro

    Tip: Boot2Docker (OSX and Windows) Installing Docker Linux? Install Docker with official packages. Kitematic (OSX)
  8. Docker Images An image is controlled by a Dockerfile docker

    build -t foo/bar . docker pull foo/bar
  9. • Static: all files and code are contained in image

    • Dynamic: link folders to actively modify code (development only) Sehr wichtig/very important/¡muy importante! Docker Images
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. ENV KEY value Declare any environment variables that will be

    passed to any RUN command. VOLUME /var/foo VOLUME [“/var/foo”, “/var/bar”] creates a mount point for volumes from host or other containers
  18. FROM centurylink/ruby-base:2.1.2 Dockerfile No need for gemset or version management,

    just use a different base image. Base images are great!
  19. Gems From Swipely: docker-api: for interacting with the Docker API

    from your Ruby application Over 30 other gems
  20. Debugging in a Container Use Pry. require ‘pry’ class Thing

    def some_method binding.pry #some brilliant broken code end end
  21. Debugging in a Container No need for a remote session*

    Alternatively, use pry command: docker run centurylink/panamax-api pry
  22. Simply put, Docker architecture is service-oriented architecture. If a service

    fails, new containers can be spun up in milliseconds.
  23. Configuration can happen in two places: The Dockerfile, by baking

    config options into the service’s base image The docker run string, by specifying configuration options with various flags Configuring an Application
  24. Bind 8080:4567 The Dockerfile Link: DB Web FROM centurylink/ruby-base:2.1.2 MAINTAINER

    Laura Frank <[email protected]> RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD ["ruby", "hello_world.rb"]
  25. Bind 8080:4567 FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <[email protected]> ENV APIKEY=superSeCrEt01234567abcdef!

    RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD ["ruby", "hello_world.rb"] The Dockerfile Link: DB Web
  26. Bind 8080:4567 Link: DB The Docker Run String Web docker

    run -p 8080:4567 -e “APIKEY=superSeCrEt01234567abcdef!” —-link db:db my-image
  27. The Docker Run String Each container has own docker run

    string Can only start one container at a time via CLI Multiple containers can run from the same image Find balance between docker run and Dockerfile
  28. Application Templating Use your own images, or images from the

    Docker Registry Specify config options beforehand Run applications with one or two simple commands
  29. Docker workflow tool Itself a containerized application panamax.io Uses CoreOS,

    Fleet, and etcd for orchestration and service discovery
  30. --- 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: []
  31. Parting Thoughts Extract commonalities from images in order to share

    them Don’t include any user- or org-specific configurations in an image or application template Boot2Docker Use an application template