- Create simple
Gemfile
source 'https://rubygems.org'
gem 'rails', '~> 6.1`- Create empty
Gemfile.lock
touch Gemfile.lock- Create
Dockerfile
FROM ruby:2.6.8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y -qq nodejs && npm install --global yarn
RUN mkdir /app
WORKDIR /app
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install
ADD . /app- Create
docker-compose.yml
version: '3.3'
services:
db:
image: postgres:12-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: app_database
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5433
app:
build: .
command: bundle exec rails s -p 3000 -b 0.0.0.0
environment:
POSTGRES_HOST: db
volumes:
- '.:/app'
ports:
- 3001:3000
depends_on:
- db
links:
- db- Inside folder run command
docker-compose run app rails new . --force --database=postgresql --skip-bundle
- After creating app edit
config/database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: <%= ENV['PG_DB'] %>
username: <%= ENV['PG_USER'] %>
password: <%= ENV['PG_PASSWORD'] %>
host: <%= ENV['PG_HOST'] %>
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>- Add environment variables to
docker-compose.ymlinapp:part
environment:
PG_DB: app_database
PG_USER: postgres
PG_PASSWORD: postgres
PG_HOST: db-
Run
docker-compose build. This install all gems. NOTE: If there are some problems with rights need to run commandsudo chown -R $USER:$USER /path/to/app -
Run migrations, generators, etc. For example run migrations.
docker-compose run --rm app rake db:migrate
- Install webpacker
docker-compose run --rm app rails webpacker:install
- Up application.
docker-compose up
and open page http://localhost:3001