diff --git a/Dockerfile b/Dockerfile
index 9b3c6b07ba979ba9e1db829ef5c6337b18763fe7..18c83c5ec89d774fb6cbe006e7df90e60e32ab11 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -44,19 +44,24 @@ RUN curl --silent --location https://deb.nodesource.com/setup_4.x | bash - \
 
 RUN git clone --branch v${DISCOURSE_VERSION} https://github.com/discourse/discourse.git . \
  && git remote set-branches --add origin tests-passed \
- && bundle config build.nokogiri --use-system-libraries \
- && bundle install --deployment --without test --without development
+ && bundle config build.nokogiri --use-system-libraries
 
 # install additional gems
 # 
 # this expects a space-separated list of gem names
 ARG DISCOURSE_ADDITIONAL_GEMS=
 RUN if [ "$DISCOURSE_ADDITIONAL_GEMS" != "" ]; then \
+        echo >> Gemfile \
+        echo '### DISCOURSE_ADDITIONAL_GEMS' >> Gemfile \
         for GEM_NAME in $DISCOURSE_ADDITIONAL_GEMS; do \
-            bundle exec gem install "$GEM_NAME"; \
+            # add the gem to the Gemfile
+            echo "gem \"$GEM_NAME\"" >> Gemfile; \
         done; \
     fi
 
+# run bundler
+RUN bundle install --deployment --without test --without development
+    
 # install discourse plugins
 # assumptions: no spaces in URLs (urlencoding is a thing)
 #