Docker for Rails Developers

Book description

Docker does for DevOps what Rails did for web development--it gives you a new set of superpowers. Gone are "works on my machine" woes and lengthy setup tasks, replaced instead by a simple, consistent, Docker-based development environment that will have your team up and running in seconds. Gain hands-on, real-world experience with a tool that's rapidly becoming fundamental to software development. Go from zero all the way to production as Docker transforms the massive leap of deploying your app in the cloud into a baby step.

Docker makes life as a Ruby and Rails developer easier. It helps build, ship, and run your applications, solving major problems you face every day. It allows you to run applications at scale, adding new resources as needed. Docker provides a reliable, consistent environment that's guaranteed to work the same everywhere.

Docker lets you do all things DevOps without needing a PhD in infrastructure and operations. Want to spin up a cluster to run your app? No problem. Scale it up or down at will? You bet. Start by running a Ruby script without having Ruby installed on the local machine. Then Dockerize a Rails application and run it using containers, including creating your own custom Docker images tailored for running Rails apps. Describe your app declaratively using Docker Compose, specifying the software dependencies along with everything needed to run the application. Then set up continuous integration, as well as your deployment pipeline and infrastructure. Along the way, find out the best practices for using Docker in development and production environments.

This book gives you a solid foundation on using Docker and fitting it into your development workflow and deployment process.



What You Need:

All you need is a Windows, Mac OS X or Linux machine to do development on. This book guides you through the process of installing Docker. Some basic familiarity with Linux/Unix is recommended even if you're using a Windows machine.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgements
  2.  Introduction
    1. What Is Docker?
    2. Why Use Docker?
    3. Who Should Read This Book?
    4. What’s in This Book?
    5. How to Read This Book
    6. Which Operating Systems Are Supported?
    7. Online Resources
  3. Part I. Development
    1. 1. A Brave New World
      1. Installing Docker
      2. Verifying Your Install
      3. Before We Begin
      4. Running a Ruby Script Without Ruby Installed
      5. Generating a New Rails App Without Ruby Installed
      6. Quick Recap
    2. 2. Running a Rails App in a Container
      1. How Do We Run Our Rails App?
      2. Defining Our First Custom Image
      3. Building Our Image
      4. Running a Rails Server with Our Image
      5. Reaching the App: Publishing Ports
      6. Binding the Rails Server to IP Addresses
      7.  Quick Recap
    3. 3. Fine-Tuning Our Rails Image
      1. Naming and Versioning Our Image
      2. A Default Command
      3. Ignoring Unnecessary Files
      4. The Image Build Cache
      5. Caching Issue 1: Updating Packages
      6. Caching Issue 2: Unnecessary Gem Installs
      7. The Finishing Touch
      8. Quick Recap
    4. 4. Describing Our App Declaratively with Docker Compose
      1. Getting Started with Compose
      2. Launching Our App
      3. Mounting a Local Volume
      4. Starting and Stopping Services
      5. Other Common Tasks
      6. Quick Recap
    5. 5. Beyond the App: Adding Redis
      1. Starting a Redis Server
      2. Manually Connecting to the Redis Server
      3. How Containers Can Talk to Each Other
      4. Our Rails App Talking to Redis
      5. Starting the Entire App with Docker Compose
      6. Quick Recap
    6. 6. Adding a Database: Postgres
      1. Starting a Postgres Server
      2. Connecting to Postgres from a Separate Container
      3. Connecting Our Rails App to Postgres
      4. Using the Database in Practice
      5. Decoupling Data from the Container
      6. Quick Recap
    7. 7. Playing Nice with JavaScript
      1. The JavaScript Front-End Options
      2. Rails JavaScript Front End with Webpacker
      3. Compiling Assets with Webpacker
      4. A Hello World React App
      5. Quick Recap
    8. 8. Testing in a Dockerized Environment
      1. Setting Up RSpec
      2. Our First Test
      3. Setting Up Rails System Tests
      4. Running Tests That Rely on JavaScript
      5. Debugging
      6. Quick Recap
    9. 9. Advanced Gem Management
      1. The Downside to Our Existing Approach
      2. Using a Gem Cache Volume
      3. Quick Recap
    10. 10. Some Minor Irritations
      1. Rails tmp/pids/server.pid Not Cleaned Up
      2. Compose Intermittently Aborts with Ctrl-C
      3. Quick Recap
      4. Closing Thoughts on Docker in Development
  4. Part II. Toward Production
    1. 11. The Production Landscape
      1. The “Ops” in DevOps
      2. Container Orchestration
      3. A Tale of Two Orchestrators: Swarm and Kubernetes
      4. IaaS vs. CaaS
      5. Provisioning Your Infrastructure
      6. CaaS Platforms
      7. Serverless for Containers
      8. How to Decide What’s Right for Me?
      9. Quick Recap
    2. 12. Preparing for Production
      1. Configuring a Production Environment
      2. A Production Image: Precompiling Assets
      3. Sharing Images
      4. Quick Recap
    3. 13. A Production-Like Playground
      1. Creating Machines
      2. Introducing Docker Swarm
      3. Our First (Single Node) Swarm
      4. Describing Our App to Swarm
      5. Migrating the Database
      6. Deploying Our App on a Swarm
      7. Tasks and Swarm’s Scaling Model
      8. Scaling Up the Service
      9. Quick Recap
    4. 14. Deploying to the Cloud
      1. Creating a DigitalOcean Cluster
      2. Deploying to Our DigitalOcean Swarm
      3. Visualizing Containers
      4. Scale Up the Web Service
      5. Deploying to AWS Instead of DigitalOcean
      6.  Quick Recap
    5. 15. Closing Thoughts and Next Steps
      1. What Should I Learn About Next?
  5. A1. Platform Differences
    1. File Ownership and Permissions
  6. A2. Finding Images to Use
    1. Using Docker Hub
    2. Using the Docker CLI

Product information

  • Title: Docker for Rails Developers
  • Author(s): Rob Isenberg
  • Release date: February 2019
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680506754