Docker: What It Is and Why You Should Care

Docker: What It Is and Why You Should Care

A brief explanation of what Docker actually is and instructions for setting up a Rails dev environment in Docker.

4109276dec776c9999af7ba023d902b6?s=128

Alexander Clark

July 26, 2016
Tweet

Transcript

  1. Docker What It Is and Why You Should Care

  2. My Story

  3. What is Docker? Virtualization

  4. None
  5. None
  6. = Virtual Machines Guest Host

  7. = Docker Containers

  8. That’s all great. Why should I care?

  9. • Install Homebrew • brew install several packages - SQL,

    Imagemagick • Install RVM or Rbenv • Install one or more versions of Ruby • Clone one or more Git repos • Run bundle/npm/bower/etc install for each repo
  10. • Start the db server (unless it’s always running) •

    Start the rails app • Background workers? Sidekiq and Redis • SoA? Need to start those up too on the right port • iTerm or Tmux setup to run all this? Foreman? • Foreman requires same directory. Subcontractor.
  11. None
  12. • Install Docker • Clone your Git repos • Place

    your docker-compose.yml file
  13. • docker-compose up

  14. = Dev Dev

  15. = Dev CI

  16. ≈ Dev Prod

  17. Where do I start?

  18. Background: Building Blocks

  19. Background Tools

  20. • Dockerfile • docker-compose.yml

  21. Docker Engine - Dockerfile

  22. FROM ruby:2.3.1-slim RUN apt-get update -qq && apt-get install -y

    \ build-essential libpq-dev postgresql-client ENV RAILS_ROOT /var/www/myapp RUN mkdir -p $RAILS_ROOT/tmp/pids WORKDIR $RAILS_ROOT COPY Gemfile Gemfile COPY Gemfile.lock Gemfile.lock RUN gem install bundler RUN bundle install
  23. Docker Compose YAML

  24. app: build: . command: rails server --port 3000 --binding 0.0.0.0

    environment: RAILS_ENV: development DATABASE_HOST: db links: - db ports: - 3000:3000 volumes: - .:/var/www/myapp db: image: postgres:9.5.3 environment: POSTGRES_USER: username POSTGRES_PASSWORD: password volumes: - myapp-db:/var/lib/postgresql/data
  25. sidekiq: build: . command: bundle exec sidekiq environment: REDIS_URL: redis://redis:6379

    links: - db - redis volumes: - .:/var/www/myapp redis: image: redis
  26. Dockerfile docker-compose.yml

  27. Other Ways To Get Started

  28. None
  29. Takeaways • Docker reduces dev dependencies • It adds parity

    where it is used (Dev-CI-Production) • Easy to get started
  30. Questions?

  31. • Alexander Clark • Twitter @atheclark • Blog http://alexander-clark.com/blog •

    Github alexander-clark • Slack alexander-clark
  32. Thanks for listening.