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

Rails on Docker

Rails on Docker

Technical walkthrough on setting up and using Docker for Ruby on Rails application in all environments (development, test, and production).

There is also a companion article on Medium: https://medium.com/nimbl3/rails-on-docker-9cbc33b8f590

Olivier Robert

January 17, 2018
Tweet

More Decks by Olivier Robert

Other Decks in Programming

Transcript

  1. Intro Until now, Docker was limited to the development environment

    • Run services via Docker Compose e.g. Postgresql, Redis, Elastic Search ◦ Faster and reliable setup of projects ◦ Manageable colocation of projects with different services version on the same host machine ◦ Service-based architecture • Run the application in the host machine ◦ Easier debugging ◦ Less tooling
  2. Intro Why running Docker in all environments: • Test ◦

    No reliance on the CI/CD service provider for the availability of specific version of services ◦ No reliance on the CI/CD service provider caching but instead use Docker image caching • Production ◦ Less reliance on Heroku-only deployment ◦ Possibility to migrate the application to more complex deployment setup e.g. k8s ⇒ Service providers are adopting Docker container as their preferred platform of choice over their often proprietary system. Let’s be ahead of the curve!
  3. The Setup • Development ◦ Run the application in the

    host machine ◦ Run the services in Docker containers via Docker Compose • Test ◦ Run both the application and services in Docker containers via Docker Compose ◦ Run the tests inside the application container • Production ◦ Run the application processes (app, worker) in Docker containers ◦ Use Heroku add-ons for services such as databases
  4. The Setup Docker Compose 3.2 is required to use the

    latest Docker caching capabilities
  5. Where does the cache come from? Docker Images are stored

    in registries (~ repositories) Docker Hub Google Container Registry Heroku Registry Local Machine CI/CD Heroku AWS Digital Ocean AMZ EC2 Container Registry quay.io Google Cloud
  6. CI/CD Setup (Semaphore) • Leverage caching by first pulling the

    Docker image for the current branch • Then run the rest of application setup and tests
  7. CI/CD Setup (Semaphore) Build time on first build: no cache

    Build time on subsequent builds: with cache
  8. Heroku Setup • Heroku does NOT support Docker Compose so

    only the application can be deployed as a Docker container. For services use Heroku add-ons. • Multi-process application needs multiple Dockerfiles with distinct CMD
  9. Docker Images booting time • Heroku will kill any application

    within 60 seconds • Docker Containers can be killed and restarted So the Dockerfile needs to contain all build steps required for the application to start without any delay: • Setup all dependencies (ruby/JS) • Precompile all assets • Execute any scripts necessary e.g. rake tasks
  10. Next Steps • Reduce image sizes by using alpine base

    images • Change image tagging using the branch name chore/setup-living-style-guide ⇒ chore-setup-living-style-guide
  11. Thanks! Contact Nimbl3 [email protected] 399 Sukhumvit Road, Interchange 21 Klongtoey

    nua, Wattana Bangkok 10110 20th Floor, Central Tower 28 Queen's Road Central, Hong Kong nimbl3.com