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

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.

Alexander Clark

July 26, 2016
Tweet

More Decks by Alexander Clark

Other Decks in Programming

Transcript

  1. Docker
    What It Is and Why You Should Care

    View full-size slide

  2. What is Docker?
    Virtualization

    View full-size slide

  3. =
    Virtual Machines
    Guest
    Host

    View full-size slide

  4. =
    Docker Containers

    View full-size slide

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

    View full-size slide

  6. • 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

    View full-size slide

  7. • 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.

    View full-size slide

  8. • Install Docker
    • Clone your Git repos
    • Place your docker-compose.yml file

    View full-size slide

  9. • docker-compose up

    View full-size slide

  10. Where do I start?

    View full-size slide

  11. Background:
    Building Blocks

    View full-size slide

  12. Background
    Tools

    View full-size slide

  13. • Dockerfile
    • docker-compose.yml

    View full-size slide

  14. Docker Engine - Dockerfile

    View full-size slide

  15. 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

    View full-size slide

  16. Docker Compose YAML

    View full-size slide

  17. 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

    View full-size slide

  18. sidekiq:
    build: .
    command: bundle exec sidekiq
    environment:
    REDIS_URL: redis://redis:6379
    links:
    - db
    - redis
    volumes:
    - .:/var/www/myapp
    redis:
    image: redis

    View full-size slide

  19. Dockerfile
    docker-compose.yml

    View full-size slide

  20. Other Ways To Get Started

    View full-size slide

  21. Takeaways
    • Docker reduces dev dependencies
    • It adds parity where it is used (Dev-CI-Production)
    • Easy to get started

    View full-size slide

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

    View full-size slide

  23. Thanks for listening.

    View full-size slide