How to install import script gem dependencies?

I recommend adding your dependency to the Gemfile and using bundler to install the gems. Run this inside the Docker container:

cd /var/www/discourse
echo "gem 'my_gem'" >> Gemfile
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

And you need to run your import script as user discourse as well:

su discourse -c 'bundle exec ruby script/import_scripts/my_import_script.rb