This is my first post, so please point out any mistakes. Also, I hope this post will help you launch the rails 5.2 production environment with docker.
It is mainly divided into four parts.
First of all, the following four are mainly required to start in the production environment with rails 5.2
In docker, describe the part necessary for starting and start it
Set database.yml and set DB connection etc.
database.yml
production:
<<: *default
database:
username:
password:
I think you can check if you can run the following command with docker
EDITOR=vim rails credentials:edit
I was using docker-compose, so I'm checking with the following command
docker-compose run -e EDITOR=vim web rails credentials:edit
You need to precompile the rails assets file
RAILS_ENV=production bundle exec rails assets:precompile
I added the following description and started it
Dockerfile
ENV RAILS_ENV="production"
RUN SECRET_KEY_BASE=production bundle exec rails assets:precompile
Well, when I started it, the following error came out.
`validate_secret_key_base': Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit` (ArgumentError)
The content is "Cannot start because the secret_key_base value cannot be found". So I searched on the net and tried to solve the error, but I couldn't.
I solved it by trying the following sites https://qiita.com/laser_beam/items/b4abdfed09fd987308fb
Specifically, I solved it by putting a space in SECRET_KEY_BASE in the credentials.yml.enc file. before
enc:credentials.yml.enc
secret_key_base: *****************************
after
enc:credentials.yml.enc
secret_key_base: *****************************
↑ There will be a space
I don't know the cause, but if you can't solve it, you may want to try it.
I solved it in an unexpected way, so I thought it was important to try what I could.
Recommended Posts