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

Real World Docker for the Rubyist

Real World Docker for the Rubyist

Docker’s gotten a lot of press, but how does it fare in the real world Rubyists inhabit every day?

Together we’ll take a deep dive into how a real company transformed itself to run on Docker. We’ll see how to build and maintain Docker images tailored for Ruby. We’ll dig into proper configuration and deployment options for containerized applications. Along the way we’ll highlight the pitfalls, bugs and gotchas that come with such a young, fast moving platform like Docker.

Whether you’re in production with Docker or just dabbling, come learn how Docker and Ruby make an awesome combination.

Jason R Clark

May 06, 2016
Tweet

More Decks by Jason R Clark

Other Decks in Technology

Transcript

  1. I'm Jane, a new New Relic with a cool new

    feature to deploy! I'm Jill, an experienced Relic, ready to help
  2. This document and the information herein (including any information that

    may be incorporated by reference) is provided for informational purposes only and should not be construed as an offer, commitment, promise or obligation on behalf of New Relic, Inc. (“New Relic”) to sell securities or deliver any product, material, code, functionality, or other feature. Any information provided hereby is proprietary to New Relic and may not be replicated or disclosed without New Relic’s express written permission. Such information may contain forward-looking statements within the meaning of federal securities laws. Any statement that is not a historical fact or refers to expectations, projections, future plans, objectives, estimates, goals, or other characterizations of future events is a forward-looking statement. These forward-looking statements can often be identified as such because the context of the statement will include words such as “believes,” “anticipates,” “expects” or words of similar import. Actual results may differ materially from those expressed in these forward-looking statements, which speak only as of the date hereof, and are subject to change at any time without notice. Existing and prospective investors, customers and other third parties transacting business with New Relic are cautioned not to place undue reliance on this forward-looking information. The achievement or success of the matters covered by such forward-looking statements are based on New Relic’s current assumptions, expectations, and beliefs and are subject to substantial risks, uncertainties, assumptions, and changes in circumstances that may cause the actual results, performance, or achievements to differ materially from those expressed or implied in any forward-looking statement. Further information on factors that could affect such forward-looking statements is included in the filings we make with the SEC from time to time. Copies of these documents may be obtained by visiting New Relic’s Investor Relations website at ir.newrelic.com or the SEC’s website at www.sec.gov. New Relic assumes no obligation and does not intend to update these forward-looking statements, except as required by law. New Relic makes no warranties, expressed or implied, in this document or otherwise, with respect to the information provided.
  3. 5

  4. 14 FROM ruby:2.3 WORKDIR /data/app COPY Gemfile Gemfile.lock /data/app RUN

    bundle install --deployment ADD . /data/app CMD ["unicorn", "--config", "..."] Dockerfile ?
  5. $terminal >>> 17 $ docker build -t loc-service . Sending

    build context to Docker daemon Step 1 : FROM newrelic/base-builder 2.3: Pulling from newrelic/base-builder ... ---> 7ca70eb2dfea Step 2 : COPY . /data/app ---> 9f54fdf6b489 Removing intermediate container 669fd221 ... Step 14 : CMD supervisord Removing intermediate container 5247f58d Successfully built 1773de8387dc $
  6. $terminal >>> 18 $ docker images REPOSITORY TAG IMAGE ID

    CREATED loc-service latest sha256:1773d 4 min ago
  7. $terminal >>> 22 $ docker run loc-service CRIT Supervisor running

    as root (no user in config file) WARN Included extra file "/etc/supervisord.d/app.conf" during parsing WARN Included extra file "/etc/supervisord.d/nginx.conf" during parsing WARN Included extra file "/etc/supervisord.d/ permissions.conf" during parsing INFO supervisord started with pid 1 INFO spawned: 'fix-permissions' with pid 8 INFO spawned: 'web-unicorn' with pid 9 INFO spawned: 'nginx' with pid 10 ...
  8. 23

  9. 24

  10. 25 namespace :environment do desc 'Staging environment' task :staging =>

    :common do set :image, 'newrelic/loc-service' host 'staging-1.nr-internal.net' host 'staging-2.nr-internal.net' end end centurion-config/loc-service.rake
  11. 26 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/loc-service' host 'staging-1.nr-internal.net' host 'staging-2.nr-internal.net' end end centurion-config/loc-service.rake
  12. 27 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/loc-service' host 'staging-1.nr-internal.net' host 'staging-2.nr-internal.net' end end centurion-config/loc-service.rake
  13. 28 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/loc-service' host 'staging-1.nr-internal.net' host 'staging-2.nr-internal.net' end end centurion-config/loc-service.rake
  14. $terminal >>> 32 $ centurion -e staging \ -p loc-service

    \ -a deploy ...Fetching image loc-service:latest ...Using CLI to pull latest -- Connecting to staging-1.nr-internal.net RESOLVED loc-service:latest => 999cd48e588d ** Invoke deploy:verify_image (first_time) ** Execute deploy:verify_image -- Connecting to staging-1.nr-internal.net .... Found container up for 6 seconds Container is up!
  15. $terminal >>> 33 $ centurion -e staging \ -p loc-service

    \ -a deploy ...Fetching image loc-service:latest ...Using CLI to pull latest -- Connecting to staging-1.nr-internal.net RESOLVED loc-service:latest => 999cd48e588d ** Invoke deploy:verify_image (first_time) ** Execute deploy:verify_image -- Connecting to staging-2.nr-internal.net .... Found container up for 6 seconds Container is up!
  16. $terminal >>> 34 $ centurion -e staging \ -p loc-service

    \ -a deploy ...Fetching image loc-service:latest ...Using CLI to pull latest -- Connecting to staging-1.nr-internal.net RESOLVED loc-service:latest => 999cd48e588d ** Invoke deploy:verify_image (first_time) ** Execute deploy:verify_image -- Connecting to staging-2.nr-internal.net .... Found container up for 6 seconds Container is up!
  17. 35

  18. 36

  19. 40

  20. $terminal >>> 42 $ docker -H tcp://staging-1.nr-internal.net:2375 ps CONTAINER ID

    IMAGE COMMAND 5189764ce084 loc-service "supervisord"
  21. $terminal >>> 43 $ docker -H tcp://staging-1.nr-internal.net:2375 ps CONTAINER ID

    IMAGE COMMAND 5189764ce084 loc-service "supervisord" $ docker -H tcp://staging-1.nr-internal.net:2375 \ exec -it 5189764ce084 bash [root@5189764ce084 /]#
  22. 45 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/loc-service' memory 2.gigabytes host 'staging-1.nr-internal.net' host 'staging-2.nr-internal.net' end end centurion-config/loc-service.rake
  23. $terminal >>> 48 $ docker run -it -e UNICORN_WORKERS=3 loc-service

    bash [root@5189764ce084 /]# env ... UNICORN_WORKERS=3
  24. 49 ... # how many worker processes to start worker_processes

    ENV["UNICORN_WORKERS"].to_i unicorn_config.rb
  25. 52 module MyRailsApp class Application < Rails::Application config.service_url = (ENV['SERVICE_URL']

    || 'http://...') config.service_timeout = (ENV['SERVICE_TIMEOUT'] || 5).to_f end end config/application.rb
  26. 54

  27. 56

  28. 58 FROM newrelic/centos:6 ... RUN rbenv install 2.3.0 # Install

    supervisord... RUN easy_install supervisor # Install nginx... RUN yum install -y nginx base-builder/Dockerfile
  29. 59 FROM newrelic/centos:6 ... RUN rbenv install 2.3.0 RUN gem

    install bundler RUN rbenv rehash ... base-builder/Dockerfile
  30. 60 FROM newrelic/centos:6 ... RUN rbenv install 2.3.0 RUN gem

    install bundler RUN rbenv rehash RUN bundle install ... base-builder/Dockerfile
  31. $terminal >>> 61 $ docker build -t newrelic/base-builder . ...

    Step 3 : RUN bundle install ---> Running in cb91de794b44 Could not locate Gemfile
  32. 62 FROM newrelic/centos:6 ... RUN rbenv install 2.3.0 RUN gem

    install bundler RUN rbenv rehash ONBUILD COPY Gemfile* . ONBUILD RUN bundle install base-builder/Dockerfile
  33. 70 [program:web-unicorn] command=bundle exec unicorn -c config/unicorn_config.rb autostart=true autorestart=true directory=/data/app

    user=nobody stdout_logfile = /dev/stdout stdout_logfile_maxbytes = 0 stderr_logfile = /dev/stderr stderr_logfile_maxbytes = 0 /etc/supervisord.d/web-unicorn.conf
  34. $terminal >>> 73 $ docker run loc-service bundle exec rake

    /Users/jclark/.rbenv/versions/2.2.4/bin/ruby ... Randomized with seed 22351 ................. Finished in 0.23058 seconds (files took 2.86 seconds to load) 17 examples, 0 failures Randomized with seed 22351 $
  35. $terminal >>> 74 $ docker build -t loc-service . &&

    \ docker run loc-service bundle exec rake docker build . Sending build context to Docker daemon... Step 1 : FROM newrelic/base-builder # Executing 12 build triggers... ... ... ... /Users/jclark/.rbenv/versions/2.2.4/bin/ruby ... ...
  36. $terminal >>> 75 $ docker build -t loc-service . &&

    \ docker run loc-service bundle exec rake docker build . Sending build context to Docker daemon... Step 1 : FROM newrelic/base-builder # Executing 12 build triggers... ... ... ... /Users/jclark/.rbenv/versions/2.2.4/bin/ruby ... ...
  37. $terminal >>> 76 $ docker run -it \ -v /src/my-app:/test-app

    \ loc-image \ "cd /test-app && bundle exec rake"
  38. 78 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/redis' memory 1.gigabytes host 'staging-3.nr-internal.net' env_vars REDIS_MAXMEMORY: '1G' env_vars REDIS_PWD: 'WOULDNTYOULIKETOKNOW' end centurion-config/loc-redis.rake
  39. 79 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/redis' memory 1.gigabytes host 'staging-3.nr-internal.net' env_vars REDIS_MAXMEMORY: '1G' env_vars REDIS_PWD: 'WOULDNTYOULIKETOKNOW' end centurion-config/loc-redis.rake
  40. 80 namespace :environment do desc 'Staging environment' task :staging do

    set :image, 'newrelic/redis' memory 1.gigabytes host 'staging-3.nr-internal.net' env_vars REDIS_MAXMEMORY: '1G' env_vars REDIS_PWD: 'WOULDNTYOULIKETOKNOW' end centurion-config/loc-redis.rake
  41. 82

  42. 83

  43. 84