$ rails db:system:change --to=postgresql
#Dockerfile
FROM ruby:2.7.1 #Match the version. Check with Gemfile
RUN curl https://deb.nodesource.com/setup_12.x | bash
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y nodejs yarn postgresql-client
RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y postgresql-client --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN gem install bundler
RUN bundle install
ADD . /myapp
↑ I got various errors and I went with this, but I still get a warning. Pien
#docker-compose.yml
version: '3'
services:
db:
image: postgres
ports:
- '5432:5432'
volumes:
- postgresql-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=password # If you do not set an arbitrary password, an error will occur.
web:
build:
context: .
dockerfile: Dockerfile
command: bundle exec rails s -p 3000 -b '0.0.0.0'
tty: true
stdin_open: true
depends_on:
- db
ports:
- "3000:3000"
volumes:
- .:/myapp #Source code changes are immediately reflected in Docker
volumes:
postgresql-data:
driver: local
database.yml
#Comment out omitted
#password is docker-compose.What was set in yml
default: &default
adapter: postgresql
encoding: utf8
host: db
username: postgres
password: password
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: mayby_docker_development
#Comment out omitted
test:
<<: *default
database: mayby_docker_test
#Comment out omitted
production:
<<: *default
database: mayby_docker_production
username: mayby_docker
password: <%= ENV['MAYBY_DOCKER_DATABASE_PASSWORD'] %>
webpacker.yml
check_yarn_integrity: false
#default,It seemed to be useless unless both development were set to false.
$ docker-compose build
Create a DB and migrate.
$ docker-compose run web rake db:create db:migrate
If it is displayed at local: 3000, it seems that it was done for the time being.
$ docker-compose up
[Rails] What to do if "Cannot render console from
config/environment/development.rb
config.web_console.whitelisted_ips = 'Rejected IP address'
I did, but there are still others
There was something called a segmentation fault related to SaaS. When I try to google with the last power,
Resolved an issue with Rails 6 segfaulting
There was a god-like blog.
assets.rb
#Stop parallel compilation of asetts (countermeasures against segmentation errors)
Rails.application.config.assets.configure do |env|
env.export_concurrent = false
end
It is said that a countermeasure gem will be released, but I am not sure yet, so I will wait for a while.
Recommended Posts