Launching the production environment with docker + rails (ver5.2) and errors that occurred

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.


Article content

It is mainly divided into four parts.

How do I need to set it up for production with rails?

First of all, the following four are mainly required to start in the production environment with rails 5.2

  1. Set up the production environment in database.yml or database
  2. Check if SECRET_KEY_BASE exists in credentials.yml.enc
  3. Perform asset precompilation
  4. Start the server

Setting method with docker

In docker, describe the part necessary for starting and start it

Database related

Set database.yml and set DB connection etc.


  <<: *default

Checking SECRET_KEY_BAS in credentials.yml.enc

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

Asset precompile

You need to precompile the rails assets file

RAILS_ENV=production bundle exec rails assets:precompile

Part to describe in docker

I added the following description and started it


ENV RAILS_ENV="production"

RUN SECRET_KEY_BASE=production bundle exec rails assets:precompile

Error that occurred at startup

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.

Error solution

I solved it by trying the following sites

Specifically, I solved it by putting a space in SECRET_KEY_BASE in the credentials.yml.enc file. before


secret_key_base: *****************************



 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.

At the end

I solved it in an unexpected way, so I thought it was important to try what I could.

Referenced articles

Recommended Posts

Launching the production environment with docker + rails (ver5.2) and errors that occurred
[Docker] List of errors that occurred when building the environment
Building Rails 6 and PostgreSQL environment with Docker
Build WordPress environment with Docker (Local) and AWS (Production)
[Docker] Rails 5.2 environment construction with docker
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
Create Rails5 and postgresql environment with Docker and make pgadmin available
Rails + MySQL environment construction with Docker
Build Rails environment with Docker Compose
[Environment construction with Docker] Rails 6 & MySQL 8
Super beginner builds Rails6 + Postgresql environment with Docker to the end
Rails environment construction with Docker (personal apocalypse)
Create Rails 6 + MySQL environment with Docker compose
Prepare the format environment with "Rails" (VScode)
Show Better Errors in Rails + Docker environment
[Rails] Reset the database in the production environment
How to build Rails 6 environment with Docker
I built a rails environment with docker and mysql, but I got stuck
Settings that should be done when operating a production environment with Rails
[Rails] About the error that the image is not displayed in the production environment
(Basic authentication) environment variables in rails and Docker
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
Rails development environment created with VSCode and devcontainer
Prepare a scraping environment with Docker and Java
[Rails] How to build an environment with Docker
How to deal with the error yaml.scanner.ScannerError: while scanning for the next token that appeared in Rails environment construction with Docker
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
Now that you have deployed AWS with Rails On Docker, let's organize the contents.
Compiled kotlin with cli with docker and created an environment that can be executed with java
Docker the development environment of Ruby on Rails project
[First team development ③] Share the development environment created with Docker
Note that I stumbled upon building the Rails environment
Prepare the environment for java11 and javaFx with Ubuntu 18.4
A command that definitely cleans the local docker environment
Addicted to the webpacker that comes standard with Rails 6
SSL in the local environment of Docker / Rails / puma
Build Rails (API) x MySQL x Nuxt.js environment with Docker
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Debug the VSCode + Docker + PHP development environment with XDebug.
Rails deploy with Docker
Production environment and credentials.yml.enc
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Easy environment construction of MySQL and Redis with Docker and Alfred
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
How to build Rails, Postgres, ElasticSearch development environment with Docker
Build a Node-RED environment with Docker to move and understand
[Docker] The story that an error occurred in docker-compose up
Building an environment for creating apps with Rails and Vue
Organize communication in an environment that uses various resources on the host machine and Docker container
How to make an application with ruby on rails (assuming that the environment has been built)
Docker settings and this and that
Build docker environment with WSL
[Rails] strftime this and that
React environment construction with Docker
[Docker] Use whenever with Docker + Rails
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Can't output PDF in production environment (EC2, Amazon Linux) with Rails
I tried to build the environment of PlantUML Server with Docker