Dockerize Rails (With Docker Compose)

Public
Copy the "Ruby Starter Kits" template to your existing project.
Icons/chart bar
Used 25 times
Created by
M Mike Rogers

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/VWesw6"
Template Source

Review the code before running this template on your machine.

require "open-uri"

base_uri = "https://raw.githubusercontent.com/Ruby-Starter-Kits/Docker-Rails-Generator/master/App-Template/"

files = [
  ".github/workflows/tests.yml",
  "config/cable.yml",
  "config/database.yml",
  ".dockerignore",
  "docker-compose.ci.yml",
  "docker-compose.yml",
  "Dockerfile"
]

files.each do |file_path|
  file file_path, URI.parse("#{base_uri}#{file_path}").open.read
end

if yes?("Build Docker Environment?")
  run("docker-compose build && docker-compose run --rm web bin/setup")

  if yes?("Start Your Ruby on Rails App?")
    run("docker-compose up")
  else
    run("docker-compose down")
  end
end
Comments

Sign up or Login to leave a comment.