状況
Dockerのコンテナ内でcredentials.yml.encを編集しようとするとエラーが出てしまいます。credentials.yml.encとmaster.keyの関係が悪いと思い両方とも消してからEDITOR=vim rails credentials:editを行っても再生成されない状況です。
#行ったこと
ホスト環境でRaiils newをしたあとにbundle exec rails db:create db:migrateを実行
その後buildをし、コンテナを起動しています。
わからないこと
今回はホスト環境でrails newをしたものを無理やりコンテナ化しているのでホスト環境とコンテナ内とのカーネルのズレからRailsが正しく実行されないのでしょうか?
ちなみにこちらを 参考にコンテナ内でRails newをした場合はコンテナ内で編集できて、ホスト環境では編集できませんでした。
エラー文
Dockerのコンテナ内でcredentials.yml.encを編集しようとした際のエラーです
Traceback (most recent call last): 37: from bin/rails:3:in `<main>' 36: from bin/rails:3:in `load' 35: from /SubscripS/bin/spring:15:in `<top (required)>' 34: from /SubscripS/bin/spring:15:in `require' 33: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' 32: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' 31: from /usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' 30: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' 29: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call' 28: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' 27: from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' 26: from /SubscripS/bin/rails:9:in `<top (required)>' 25: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require' 24: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' 23: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require' 22: from /usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' 21: from /usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi' 20: from /usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 19: from /usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi' 18: from /usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require' 17: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands.rb:18:in `<top (required)>' 16: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/command.rb:46:in `invoke' 15: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/command/base.rb:69:in `perform' 14: from /usr/local/bundle/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch' 13: from /usr/local/bundle/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command' 12: from /usr/local/bundle/gems/thor-1.0.1/lib/thor/command.rb:27:in `run' 11: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/credentials/credentials_command.rb:26:in `edit' 10: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/command/helpers/editor.rb:26:in `catch_editing_exceptions' 9: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/credentials/credentials_command.rb:27:in `block in edit' 8: from /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/credentials/credentials_command.rb:50:in `change_credentials_in_system_editor' 7: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/encrypted_file.rb:54:in `change' 6: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/encrypted_configuration.rb:21:in `read' 5: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/encrypted_file.rb:42:in `read' 4: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/encrypted_file.rb:79:in `decrypt' 3: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify' 2: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify' 1: from /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/message_encryptor.rb:183:in `_decrypt' /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
#Dockerfile
Dockerfile
FROM ruby:2.5.1 # 必要なパッケージのインストール(基本的に必要になってくるものだと思うので削らないこと) RUN apt-get update -qq && \ apt-get install -y build-essential \ libpq-dev \ nodejs # RAILS_ENV と RAILS_MASTER_KEY をあと差しできるようにしています ARG RAILS_ENV ARG RAILS_MASTER_KEY # あと差しした RAILS_ENV と RAILS_MASTER_KEY を環境変数に設定します ENV RAILS_ENV ${RAILS_ENV} ENV RAILS_MASTER_KEY ${RAILS_MASTER_KEY} # ルート直下にapp_nameという名前で作業ディレクトリを作成(コンテナ内のアプリケーションディレクトリ) RUN mkdir /app_name WORKDIR /app_name # ホストのGemfileとGemfile.lockをコンテナにコピー ADD Gemfile /app_name/Gemfile ADD Gemfile.lock /app_name/Gemfile.lock # bundle installの実行 RUN \ bundle install && \ rm -rf ~/.gem # ホストのアプリケーションディレクトリ内をすべてコンテナにコピー ADD . /app_name # RAILS_ENV が production のとき assets:precompile を実行するようにしています RUN if [ "${RAILS_ENV}" = "production" ]; then bundle exec rails assets:precompile; else export RAILS_ENV=development; fi EXPOSE 3000 CMD ["rails", "server", "-b", "0.0.0.0"]
環境
Mac OS 10.15
Ruby 2.5.1
Rails 5.2.4.1
Docker 19.03.5
回答2件
あなたの回答
tips
プレビュー