'Docker configuration for ruby 2.7 and Rails 7

i am trying to containerise my rails application after upgrading it to Rails 7

below is the relevant part of my docker file


FROM ubuntu:20.04

#https://www.postgresql.org/download/linux/ubuntu/
RUN apt-get update && apt-get install -y gnupg wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Import the repository signing key:
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

RUN apt-get update && apt-get dist-upgrade -y && DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs ruby-dev bundler build-essential zlib1g-dev libpq-dev tzdata git curl postgresql-client-12 imagemagick && rm -rf /var/lib/apt/lists/*

RUN useradd -m deploy

WORKDIR /app

COPY Gemfile* ./
RUN mkdir -p vendor
COPY vendor/cache vendor/cache
RUN bundle config set deployment 'true'
RUN bundle config set without 'test development'
RUN bundle install

i see the following error

#17 1.447 Don't run Bundler as root. Bundler can ask for sudo if it is needed, and                                                                                                                              
#17 1.447 installing your bundle as root will break this application for all non-root                                                                                                                           
#17 1.447 users on this machine.                                                                                                                                                                                
#17 2.044 Some gems seem to be missing from your vendor/cache directory.
#17 2.044 Could not find rake-13.0.6 in any of the sources
------
executor failed running [/bin/sh -c bundle install]: exit code: 7

any help on how to address this will be really great, thanks.



Solution 1:[1]

After you add your user, you need to switch to it in order for subsequent commands to no longer run as root:

RUN useradd -m deploy
USER deploy

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J c