0

I am trying to dockerized an existing rails application which has postgres as a database

here is my docker file

# Use Ruby 3.1.2 as the base image
FROM ruby:3.1.2

ADD . /budget_app

WORKDIR /budget_app

# RUN rake db:create
COPY Gemfile /budget_app/Gemfile
COPY Gemfile.lock /budget_app/Gemfile.lock
RUN bundle install
CMD ["rails", "server"]

# RUN bundle install

RUN apt-get update && apt-get install -y shared-mime-info
RUN EDITOR="vi --wait" bin/rails credentials:edit

ENV RAILS_ENV development
ENV RAILS_SERVE_STATIC_FILES true


EXPOSE 3000

CMD ["bash"]

Here is my docker Compose yaml file

version: '3.9'
services:
  db:
    image: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    volumes:
      - postgres:/var/lib/postgresql/data
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/Rails-Docker
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment:
      - RAILS_MASTER_KEY=a1b327738783b07f05a26a08a1766976

Here is the terminal output while running the docker the database is working fine but have issue running this web-app

budget-app-web-1  | => Booting Puma
budget-app-web-1  | => Rails 7.0.1 application starting in production 
budget-app-web-1  | => Run `bin/rails server --help` for more startup options
budget-app-web-1  | Exiting
budget-app-web-1  | /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:208:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:185:in `_decrypt'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:159:in `decrypt_and_verify'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_file.rb:92:in `decrypt'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_file.rb:54:in `read'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:21:in `read'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:33:in `config'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:48:in `options'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
budget-app-web-1  |     from /usr/local/bundle/gems/activerecord-7.0.1/lib/active_record/railtie.rb:342:in `block in <class:Railtie>'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `instance_exec'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `run'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `call'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:60:in `run_initializers'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/application.rb:372:in `initialize!'
budget-app-web-1  |     from /budget_app/config/environment.rb:5:in `<main>'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in `require_relative'
budget-app-web-1  |     from config.ru:3:in `block in <main>'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:312:in `block in start'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:379:in `handle_profiling'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:311:in `start'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:38:in `start'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:143:in `block in perform'
budget-app-web-1  |     from <internal:kernel>:90:in `tap'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:134:in `perform'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/command/base.rb:87:in `perform'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/command.rb:48:in `invoke'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<main>'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from bin/rails:4:in `<main>'
budget-app-web-1  | /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:203:in `final': OpenSSL::Cipher::CipherError
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:203:in `_decrypt'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/message_encryptor.rb:159:in `decrypt_and_verify'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_file.rb:92:in `decrypt'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_file.rb:54:in `read'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:21:in `read'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:33:in `config'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/encrypted_configuration.rb:48:in `options'
budget-app-web-1  |     from /usr/local/bundle/gems/activesupport-7.0.1/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
budget-app-web-1  |     from /usr/local/bundle/gems/activerecord-7.0.1/lib/active_record/railtie.rb:342:in `block in <class:Railtie>'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `instance_exec'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `run'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `call'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
budget-app-web-1  |     from /usr/local/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/initializable.rb:60:in `run_initializers'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/application.rb:372:in `initialize!'
budget-app-web-1  |     from /budget_app/config/environment.rb:5:in `<main>'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in `require_relative'
budget-app-web-1  |     from config.ru:3:in `block in <main>'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:312:in `block in start'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:379:in `handle_profiling'
budget-app-web-1  |     from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:311:in `start'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:38:in `start'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:143:in `block in perform'
budget-app-web-1  |     from <internal:kernel>:90:in `tap'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands/server/server_command.rb:134:in `perform'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
budget-app-web-1  |     from /usr/local/bundle/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/command/base.rb:87:in `perform'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/command.rb:48:in `invoke'
budget-app-web-1  |     from /usr/local/bundle/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<main>'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from /usr/local/bundle/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
budget-app-web-1  |     from bin/rails:4:in `<main>'
budget-app-web-1 exited with code 1

I have tried some stack overflow suggestions from this link Rails: ActiveSupport::MessageEncryptor::InvalidMessage

1 Answers1

0

You have to recreate your credentials from the dokerized new path . While working on the original state , the new env is slightly modified and therefore need to be renewd RAILS_MASTER_KEY wise. You need to go through this process.

plombix
  • 396
  • 3
  • 13