Skip to content

docker-compose made easy generating rails project with database and another env.

Notifications You must be signed in to change notification settings

x1wins/rails-new-with-docker-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to generate rails new project with docker-compose

when i run command with $ rails new PROJECT with postgresql i realize struggle and tired that generate rails project files and setup database. if i got something wrong local environment such as rbenv, rvm on macOS or another OS. it's made me burnout.

docker-compose is perfect awesome developerment environment. when i generate rails project with docker-compose, i don't need any setup on local environment like ruby, rails version, database setup. docker-compose made easy setup rails project, database and another env.

rails new command with docker-compose

$ git clone https://github.com/x1wins/rails-new-with-docker-compose.git
$ cd ./rails-new-with-docker-compose
$ docker-compose run --no-deps web rails new . --force --database=postgresql

config/database.yml

$ vim config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password: password
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test

production:
  <<: *default
  database: myapp_production
  username: myapp
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Setup

docker-compose run --no-deps web bundle exec rake db:create
docker-compose run --no-deps web bundle exec rake db:migrate
docker-compose run --no-deps web bundle exec rake db:create RAILS_ENV=test
docker-compose run --no-deps web bundle exec rake db:migrate RAILS_ENV=test

or

docker-compose run --no-deps web bundle exec rake db:prepare

Start rails server

docker-compose up --build

Restart

docker-compose restart web

Console

docker-compose run --no-deps web bundle exec rails console

About

docker-compose made easy generating rails project with database and another env.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published