Running rails 8 docker image locally

Given I run the following to create a docker image of a rails application locally.

 docker build -t store-rails:latest .

When I try to run a container from that image

docker run -i -t store-rails

I get the following error message

bin/rails aborted!
ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit` (ArgumentError)

          raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/rails/config/environment.rb:5:in `<main>'
Tasks: TOP => db:prepare => db:load_config => environment
(See full trace by running task with --trace)

I am trying to run this container on my local machine to test that its working, what do I need to do to make this work?

How I solved this

  1. Created .env file touch .env.
  2. Saved SECRET_KEY_BASE to it echo "SECRET_KEY_BASE=$(bin/rails secret)" >> .env as a place to just back it up as I’m not using docker compose atm.
  3. docker run -e "SECRET_KEY_BASE=copy paste the key value here" -p 3000:3000 -i -t store-rails.