As I remember seem it is not about M1 but mini_racer has some issues with libv8, but it usualy on mac we use to do following to solve issue
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
but not sure why it is happening on your docker, another way is check where is v8 installed and change the --with url with that path.
In docker before error commit further lines, and let build done, then you can ssh in, and try to local command. Someone suggested following solution.
RUN gem install -N libv8 -v '3.16.14.13' -- --with-system-v8 \
&& bundle config --global build.libv8 --with-system-v8
You may share your dockerfile so first we can confirm it is working on normal machine and then you can try out. But of course M1 is different architecture and some programmes are not ready for it yet.