Giter Site home page Giter Site logo

rails-docker's Introduction

Rails Docker

Simple configuration to run Ruby On Rails in a Docker environment.

Documentação em PT-BR

The objective of this repository is provide a simple way to get start work in a Ruby On Rails with PostgreSQL app on Docker by simple steps and minimal files.

This solution works in Linux, MacOS and Windows, any problem feel free to create a issue.

Requirements

  • Have installed the latest version of Docker and Docker Composer.
  • Minimum knowledge about Docker and Containers.
  • Minimum knowledge about command line.

For new projects

1 - Create a folder with your project name and go to it:

mkdir your-app-name
cd your-app-name

2 - Download the four files necessary:

curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/Dockerfile -o Dockerfile
curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/docker-compose.yml -o docker-compose.yml
curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/Gemfile -o Gemfile
curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/Gemfile.lock -o Gemfile.lock

About this files

  • DockerFile: this file contains information about the container used and the command to configure him like bundle install.
  • docker-compose.yml: This file contains informations about the services of the container and the command for run the Rails app.
  • Gemfile: this file just loads Rails. It’ll be overwritten by rails new command.
  • Gemfile.lock: only a empty file necessary to build our Dockerfile.

3 - Open DockerFile and docker-compose.yml in your prefer text editor and replace all occurrences of "sandbox" for "your-app-name".

4 - Time to build the project, generate the Rails skeleton app using docker-compose run:

docker-compose run --rm app rails new . --force --database=postgresql --skip-bundle

4.1 - If you are running Docker on Linux, the files rails new created are owned by root. This happens because the container runs as the root user. Change the ownership of the new files:

sudo chown -R $USER:$USER .

5 - At this point, rails new command modify the Gemfile, so we need to run the docker-compose build command (and every time GemFile is modified, like new gems installed):

docker-compose build

6 - Now let's connect to the database, open config/database.yml and modify it to look like this

development:
  <<: *default
  database: your-app-name_development
  username: postgres
  password:
  host: postgres

test:
  <<: *default
  database: your-app-name_test
  username: postgres
  password:
  host: postgres

7 - Open config/environments/development.rb and add this line:

config.reload_classes_only_on_change = false

This is necessary so that you do not have to restart the container for each change in the .rb files.

8 - You can now boot the app with:

docker-compose up

9 - Finally, you need to create the database. In another terminal, run:

docker-compose exec app rake db:create

So, that's it! visit http://localhost:3000 to see your new Rails App running.

For existing Rails projects

1 - You only need download the two files necessary

curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/Dockerfile -o Dockerfile
curl -L https://raw.githubusercontent.com/Agilhub/rails-docker/master/docker-compose.yml -o docker-compose.yml

2 - Open DockerFile and docker-compose.yml in your prefer text editor and replace all occurrences of "sandbox" for "your-app-name".

3 - Now let's build the project, run the command below (and every time GemFile is modified, like new gems installed):

docker-compose build

4 - Let's connect to the database, open config/database.yml and modify it to look like this

development:
  <<: *default
  database: your-app-name_development
  username: postgres
  password:
  host: postgres

test:
  <<: *default
  database: your-app-name_test
  username: postgres
  password:
  host: postgres

5 - Open config/environments/development.rb and add this line:

config.reload_classes_only_on_change = false

This is necessary so that you do not have to restart the container for each change in the .rb files.

6 - You can now boot the app with:

docker-compose up

7 - Finally, you need to create the database. In another terminal, run:

docker-compose exec app rake db:create

So, that's it! visit http://localhost:3000 to see your existing Rails App running.

rails-docker's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

rhchristian

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.