You need to install git to be able to use gems from git repositories. (no rails/noob question)

I am aware of this question: You need to install git to be able to use gems from git repositories.
I am trying to host an existing project on created by someone else. Unfortunately, I am a newb in this area, so I couldn’t figure out if I can install rails, or how to rebuild this project to include rails.
I am wondering if there are other ways of solving this error. Full message here:

 => [build 2/3] COPY Gemfile* .                                            0.0s
 => ERROR [build 3/3] RUN bundle install                                   3.9s
 > [build 3/3] RUN bundle install:                                              
#0 0.477 Bundler 2.4.21 is running, but your lockfile was generated with 2.4.5. Installing Bundler 2.4.5 and restarting using that version.                     
#0 3.394 Fetching gem metadata from                      
#0 3.440 Fetching bundler 2.4.5
#0 3.548 Installing bundler 2.4.5
#0 3.899 Fetching
#0 3.909 You need to install git to be able to use gems from git repositories. For help
#0 3.909 installing git, please refer to GitHub's tutorial at
#0 3.909
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c bundle install]: exit code: 11

Normally, this can be corrected by running:

bin/rails generate dockerfile

If this doesn’t help, can you post your Dockerfile?

As far as I understand, this is not a Rails application, so I cannot use bin/rails from within its folder. I tried installing rails with gem install rails, but that still doesn’t let me run the command. Again, I apologize for the noob understanding.
Here’s the Dockerfile:

FROM ruby:$RUBY_VERSION-slim as base

# Rack app lives here

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential

# Install application gems
COPY Gemfile* .
RUN bundle install

# Final stage for app image
FROM base

# Run and own the application files as a non-root user for security
RUN useradd ruby --home /app --shell /bin/bash
USER ruby:ruby

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=ruby:ruby /app /app

# Copy application code
COPY --chown=ruby:ruby . .

# Start the server
CMD ["bundle", "exec", "rackup", "--host", "", "--port", "8080"]

Add git to the end of that line.

This worked :+1:
I think I understand what it did too - you tell it to install the package on fly instead of installing locally. This actually solved a related problem that I had with this, since I just added those to that line of the Dockerfile as well.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.