I'm trying to install Herkou-20 & Ruby 2.7.5 for my Rails App for my local machine, but I keep having to input /bin/bash before every command in order to get things to work. I've tried playing with the command SHELL ["/bin/bash", "-c"] but it didn't help clean things up.
# Use the official Heroku-20 stack as the base image
FROM heroku/heroku:20
WORKDIR /app
# Set environment variables
ENV RUBY_VERSION 2.7.5
# Install dependencies
RUN apt-get update && \
apt-get install -y build-essential libpq-dev nodejs curl gpg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install RVM and Ruby
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \
\curl -sSL https://get.rvm.io | bash -s stable && \
/bin/bash -l -c "rvm requirements" && \
/bin/bash -l -c "rvm install $RUBY_VERSION" && \
/bin/bash -l -c "rvm use $RUBY_VERSION --default"
# Install Bundler
RUN gem install bundler -v '2.3.6' --no-document
COPY Gemfile Gemfile.lock ./
# Copy the rest of the application code into the container
COPY . .
RUN gem list
RUN ls
RUN echo 'source /etc/profile.d/rvm.sh' >> /root/.bashrc
RUN /bin/bash -l -c "rvm use $RUBY_VERSION --default && which ruby && ruby -v"
RUN /bin/bash -l -c "which ruby"
RUN /bin/bash -l -c "rvm list"
RUN /bin/bash -l -c "bundle install"
# Print the shell's name
RUN /bin/bash -l -c "echo Shell: $0"
# Set the default command to run when the container starts
CMD ["/bin/bash", "-l"]
This is the (slightly abridged) output generated when installing RVM:
You don't need to worry about the
rvmgroup. But you do need to source that startup script when you launch a shell. I'd also suggest changing the shell being used from/bin/shto BASH (this is done via theSHELLcommand).Put the
rvmcommands into a separateRUNso that you get a fresh BASH instance and the effects of the startup script have been applied.You can now remove explicit invocation of
/bin/bashfrom all subsequent commands.