Giter Club home page Giter Club logo

rails-docker-dev-box's Introduction

UPDATE: You can now use the DockRails Gem to build your Docker Rails Enironment with a simple CLI

About

This is a boilerplate Docker environment for you Rails App letting you code on your Mac while running in Docker, it includes by default:

  • DB container (PGSQL or MYSQL uncomment in docker-compose.yml)
  • Redis container
  • Web container (your rails app)
  • Job Container (Sidekiq instance)

Web/Job containers sync code base from your Rails App in realtime, letting you code on you Mac and run in the same time everything from the container

Bundler Gems, DB and Redis data are persisted accross restart and you can use ByeBug or Pry out of the box with a simple command!

Pre-requisite

First install:

Steps

  1. Clone you Rails app inside the "my-rails-app" folder (If you rename it make sure to change the name in the docker-sync file)

  2. Move the scripts/ folder into your Rails App root folder

  3. Create a data/sql folder (info: adding a .gitkeep inside will make the PG container fail)

  4. Check the docker-compose.yml ENV variables for Redis/SQL and setup your database.yml in your Rails App file.

  5. Run everything

docker-sync-stack start

Important Commands

Start all containers:

  • docker-sync-stack start

Stop all containers:

  • docker-sync-stack clear

Check all containers are stopped

  • docker ps

Run command inside a container

  • docker-compose run CONTAINER COMMAND (ex: docker-compose run web rake db:migrate)

Rebuild a container in case the DockerFile change:

  • docker-compose build CONTAINER

Need to debug a container?

  • docker-compose run CONTAINER /bin/bash

Need to access ByeBug or Pry interactve shell?

  • docker attach $(docker-compose ps -q web) โš ๏ธ DO NOT use CTRL+C here or it will exit the container but use CTRL+Q+P

Type less with ZSH Alias!

vi ~/.zshrc

# Add those lines
alias dss="docker-sync-stack"
alias dbe="docker-compose run web bundle exec"
alias dbi="docker-compose run web bundle install"
function ddbug(){
  docker attach $(docker-compose ps -q $1)
}

Reload ZSH

source ~/.zshrc

And now enjoy the simple commands like:

  • dss start
  • dbe rails c
  • dbe rails restart
  • dbi
  • ddbug web

And obviously create your own!

Miscs

  • Your DB is accessible from your host machine with the 127.0.0.1 IP and using the user/password combination found in docker-compose.yml file.

Thanks to Jesal Gadhis, this project was inspired by his tutorial

rails-docker-dev-box's People

Contributors

gmontard avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.